0

in my iOS app, we have our user log-in using facebook to grab some of their information. I've included the code below that occurs when the users presses the button that reads "Log in with Facebook":

- (IBAction)toQuadAction:(id)sender {

// Query to fetch the users name and picture
NSString *query = @"SELECT name, username FROM user WHERE uid=me() ";

// Set up the query parameter
NSDictionary *queryParam = [NSDictionary dictionaryWithObjectsAndKeys:query, @"q", nil];
// Make the API request that uses FQL
[FBRequestConnection startWithGraphPath:@"/fql" parameters:queryParam HTTPMethod:@"GET"
                      completionHandler:^(FBRequestConnection *connection,
                                          id result,
                                          NSError *error) {
                          if (error) {
                              NSLog(@"Error: %@", [error localizedDescription]);
                          } else {
                              NSLog(@"My name: %@", result[@"data"][0][@"name"]);
                              NSLog(@"My username: %@", result[@"data"][0][@"username"]);


                              //SAVE TO CORE DATA
                              AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
                              NSEntityDescription *user = [NSEntityDescription entityForName:@"User" inManagedObjectContext:appDelegate.managedObjectContext];
                              NSFetchRequest *getName = [[NSFetchRequest alloc] init];
                              [getName setReturnsObjectsAsFaults:NO];
                              [getName setEntity:user];
                              NSError *error;
                              NSMutableArray *currentUser = [[appDelegate.managedObjectContext executeFetchRequest:getName error:&error] mutableCopy];

                              //SAVE THE NAME TO CORE DATA
                              [currentUser[0] setName:result[@"data"][0][@"name"]];


                              //SAVE NAME AND PICTURE TO PARSE
                              PFQuery *query = [PFQuery queryWithClassName:@"Student"];
                              [query whereKey:@"email" equalTo:[currentUser[0] valueForKey:@"email"]];
                              [query getFirstObjectInBackgroundWithBlock:^(PFObject *users, NSError *error) {
                                  if (!users){
                                      NSLog(@"The first object request failed");
                                  } else{
                                      NSLog(@"grabbed the object");
                                      //SET THE NAME IN PARSE
                                      [users setObject:result[@"data"][0][@"name"] forKey:@"name"];
                                      //SET THE IMAGE IN PARSE
                                      NSString *URLString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?width=235&height=385", result[@"data"][0][@"username"]];
                                      NSURL *picURL = [NSURL URLWithString:URLString];
                                      NSData *picData = [NSData dataWithContentsOfURL:picURL];
                                      PFFile *picture = [PFFile fileWithData:picData ];
                                      [users setObject:picture forKey:@"picture"];
                                      [users saveInBackground];
                                  }
                              }];
                          }
                          [self performSegueWithIdentifier:@"facebookToQuad" sender:sender];
                      }];
}

When I do this with a new user (in the iOS simulator), that has not already allowed my app on Facebook, I get an alert that says "The operation couldn't be completed. (com.facebook.sdk error 2.)".

I have seen this questions asked before, but I have not found a solution that fits me. For one, I am building native, not using PhoneGap or anything like that. Another thing, my internet connection seems fine. I don't have issues doing anything else.

Does anyone know of a solution to this issue? Thanks

4

2 回答 2

1

您必须确保在您的 Facebook 应用程序 ID 中启用了沙盒。

于 2013-07-26T20:04:01.660 回答
0

转到 facebook 上的应用程序,然后检查是否有带有以下文本的橙色图标此应用程序处于沙盒模式。在这种情况下,您需要做的是使用开发人员组中具有开发权限的电子邮件测试登录功能。

在其他情况下,单击“编辑应用程序”,然后添加您在 xcode 项目中使用的 bundleId。要查看它,您可以转到 .plist 文件或添加以下代码以在控制台上打印它。

NSLog(@"%@",[[NSBundle mainBundle] bundleIdentifier]);
于 2013-07-30T16:12:45.977 回答