5

我正在iOSiPad. 我已经实现Instagram API了,所以我可以从用户那里获取和使用照片。我可以用Facebook做同样的事情吗?有没有办法访问用户的图片?谢谢

4

2 回答 2

8

Graph API 是您想要开始查看您正在寻找的数据的地方。对于用户照片,请查看:用户创建的相册 - h ​​ttps://developers.facebook.com/docs/reference/api/user/ 关于照片的信息 - https://developers.facebook.com/docs/reference/api /照片/

我建议使用 Graph API 资源管理器尝试不同的查询: https ://developers.facebook.com/tools/explorer 首先确保您请求 user_photos 权限在查询中输入我/相册会为您提供登录用户的相册列表. 单击结果中的专辑 ID 可查看该专辑的信息。输入 /photos 以查看该相册的照片。

一旦您知道您想要什么,您就可以查看构建在 Graph API 和其他 API 之上的 iOS SDK,以进行身份​​验证,并针对您感兴趣的内容抓取照片。

有关发出请求的 iOS SDK 信息,请参阅: https ://developers.facebook.com/docs/reference/ios/3.1/class/FBRequestConnection#startWithGraphPath%3AcompletionHandler%3A

因此,如果您想查看一张专辑的照片,给定一个专辑 ID,您可以使用如下请求代码:

[FBRequestConnection startWithGraphPath:@"<album_id>/photos" 
    completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
       if (!error) {
           NSLog("Results: %@", result);
       }
    }
];

确保您首先请求了 user_photos 权限。

于 2012-10-31T01:49:39.723 回答
0
- (IBAction)btnFBTap:(id)sender {
    [FBSDKProfile enableUpdatesOnAccessTokenChange:YES];
    if ([FBSDKAccessToken currentAccessToken]) {
        [self FBLogin];
    } else  {

        FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
        [login
         logInWithReadPermissions: @[@"public_profile", @"user_photos"]
         fromViewController:self
         handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
             if (error) {
                 // Process error
             } else if (result.isCancelled) {
                 // Handle cancellations
             } else {
                 [self FBLogin];
                 // If you ask for multiple permissions at once, you
                 // should check if specific permissions missing
             }
         }];
    }
}

- (void)FBLogin {

    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me"
                                       parameters:@{@"fields":@"id"}]
     startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
         [[MDManager sharedInstance].loadingView hide];
         if (!error) {
             NSLog(@"fetched user:%@", result);

             // For more complex open graph stories, use `FBSDKShareAPI`
             // with `FBSDKShareOpenGraphContent`
             /* make the API call */
             FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                           initWithGraphPath:[NSString stringWithFormat:@"/%@/photos", result[@"id"]]
                                           parameters:@{@"type":@"uploaded",
                                                        @"fields":@"link,height,width"}
                                           HTTPMethod:@"GET"];
             [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                                   id result,
                                                   NSError *error) {
                 NSLog(@"%@",result); // Return uploaded photos

             }];
         }
     }];
}
于 2016-09-14T08:17:28.380 回答