如何从"个人资料专辑中获取个人资料照片"的Facebook

时间:2015-01-31 05:11:10

标签: ios objective-c facebook facebook-graph-api

我需要从个人资料相册获取个人资料图片

我知道如何直接从userId获取个人资料图片,我知道如何获取相册的照片。

问题是 -

我需要从个人资料相册中获取所有照片,并且需要在第一个位置设置个人资料照片
如果我直接从userId获取个人资料图片,之后我放置个人资料相册,那么个人资料图片将重复两次,因为它也在相册中。

所以,我需要一些解决方案,例如我识别来自个人资料相册个人资料图片

任何链接,教程,建议,想法都会有很大的帮助。

2 个答案:

答案 0 :(得分:3)

<强>更新 这肯定会对你有帮助。

[FBRequestConnection startWithGraphPath:@"me?fields=albums.fields(name,photos.fields(name,picture,source))"
                             parameters:nil
                             HTTPMethod:@"GET"
                      completionHandler:^(
                                          FBRequestConnection *connection,
                                          id result,
                                          NSError *error
                                          ) {
                          //NSLog(@"result %@",result);
                          NSString * anImage;
                          NSArray* albums = result[@"albums"][@"data"];
                          NSUInteger index = [albums indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
                              return [obj[@"name"]  isEqualToString: @"Profile Pictures"];
                          }];

                          if (index != NSNotFound) {
                              NSDictionary *profileImages = albums[index];
                              NSDictionary *photos = profileImages[@"photos"];
                              NSArray *data = photos[@"data"];

                              for (NSDictionary *picture in data) {
                                  NSString *date = picture[@"created_time"];
                                  NSString *id = picture[@"id"];
                                  NSString *pictureUrl = picture[@"picture"];
                                  NSString *sourceUrl = picture[@"source"];

                              }

                          }
                      }];

答案 1 :(得分:2)

上面的回复(下面我添加了我的回复)帮助了我。我upvote,SDK V4的更新解决方案:

[[[FBSDKGraphRequest alloc]  initWithGraphPath:@"me" parameters:@{@"fields": @"albums.fields(name,photos.fields(name,picture,source,created_time))"}]
                          startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                              //NSLog(@"result %@",result);
                              NSString * anImage;
                              NSArray* albums = result[@"albums"][@"data"];
                              NSUInteger index = [albums indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
                                  return [obj[@"name"]  isEqualToString: @"Profile Pictures"];
                              }];

                              if (index != NSNotFound) {
                                  NSDictionary *profileImages = albums[index];
                                  NSDictionary *photos = profileImages[@"photos"];
                                  NSArray *data = photos[@"data"];

                                  for (NSDictionary *picture in data) {
                                      NSString *date = picture[@"created_time"];
                                      NSString *id = picture[@"id"];
                                      NSString *pictureUrl = picture[@"picture"];
                                      NSString *sourceUrl = picture[@"source"];

                                  }

                              }
                          }];