我在我的 iPhone 应用程序中使用 Facebook SDK。我想找到用户的 Facebook 个人资料照片,为此我使用以下代码:
-(IBAction)FacebookLogin:(id)sender{
if (FBSession.activeSession.isOpen) {
[self findAlbums];
} else {
NSArray *permissions = [[NSArray alloc] initWithObjects:@"user_photos",
nil];
[FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// if login fails for any reason, we alert
if (error) {
} else if (FB_ISSESSIONOPENWITHSTATE(status)) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
[self findAlbums];
}
}];
}
}];
}
}
-(void)findAlbums {
[FBRequestConnection startWithGraphPath:@"/me/albums"
parameters:nil
HTTPMethod:@"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
NSLog(@"result::%@",result);
}];
}
Out put ---- data = ( );
这不会在数据中给出任何相册。登录的 Facebook 用户在他的个人资料中有很多相册和照片。为什么会这样?
最佳答案
只需将查找相册中的代码更改为:
[FBRequestConnection startWithGraphPath:@"me/albums"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Success! Include your code to handle the results here
NSLog(@"user events: %@", result);
NSArray *feed =[result objectForKey:@"data"];
for (NSDictionary *dict in feed) {
NSLog(@"first %@",dict);
}
} else {
// An error occurred, we need to handle the error
// Check out our error handling guide: https://developers.facebook.com/docs/ios/errors/
NSLog(@"error %@", error.description);
}
}];
关于ios - Facebook iOS SDK - 获取用户相册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25364967/