简体   繁体   English

如何从Facebook的“个人资料相册”中获取个人资料图片

[英]How to get profile picture from “profile album” of Facebook

I need to get profile picture from profile album only . 我只需要从个人资料相册中获取个人资料图片

I know how to get profile picture directly from userId and i know how to get the photos of album. 我知道如何直接从userId获取个人资料图片,也知道如何获取相册的照片。

the problem is - 问题是 -

I need to get all the photos from profile album and need to set the profile picture on first position . 我需要从个人资料相册中获取所有照片,并且需要将个人资料图片设置在第一个位置
If i get the profile picture directly from userId and after that i place the profile album photos then the profile picture will repeat twice because it's in album too. 如果我直接从userId获取个人资料图片,然后放置个人资料相册图片,则个人资料图片将重复两次,因为它也在相册中。

So, i need some solution like i'll identify the profile picture from profile album . 因此,我需要一些解决方案,例如,我将从个人资料相册中 识别 个人资料图片

any link,tutorial,suggestion,idea will be great help. 任何链接,教程,建议,思想将大有帮助。

Update This will definitely help you. 更新这一定会对您有所帮助。

[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"];

                              }

                          }
                      }];

The reply above (below once I added my reply) helps me. 上面的回复(在添加回复后的下方)对我有所帮助。 I upvote, the updated solution for SDK V4: 我支持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"];

                                  }

                              }
                          }];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM