在我的iOS應用中,我們有我們的用戶使用Facebook登錄來獲取他們的一些信息。我已經包括當用戶按下讀取「與Facebook登錄」按鈕會出現以下的代碼:com.facebook.sdk錯誤2 iOS應用使用解析
- (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];
}];
}
當我這樣做有一個新的用戶(在iPhone模擬器),還沒有已經是允許我在Facebook上的應用程序,我收到一條警告,說「操作無法完成(com.facebook.sdk錯誤2)」。
我以前見過這個問題,但我還沒有找到適合我的解決方案。首先,我建立本地,不使用PhoneGap或類似的東西。另一件事,我的互聯網連接似乎很好。我沒有其他問題。
有誰知道這個問題的解決方案?謝謝
確保在fb id中禁用沙箱。 –
是否配置了所有的應用程序url回調設置? – Wain
你明白了@Parser,謝謝。提出這個問題,我可以接受它。 –