2015-04-17 60 views
0

我正在使用解析包括Facebook SDK,我需要显示给定用户的相册列表。我可以correttly拿到相册列表:Facebook iOS SDK:获取相册的封面图片

[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"/%@/albums", self.facebookUserId] 
          completionHandler:^( FBRequestConnection *connection, id result, NSError *error) 
     { 
      // result will contain an array with your user's albums in the "data" key 
      NSArray * albumsObjects = [result objectForKey:@"data"]; 
      NSMutableArray * albums = [NSMutableArray arrayWithCapacity:albumsObjects.count]; 

      for (NSDictionary * albumObject in albumsObjects) 
      { 
       //DO STUFF 
      } 
      self.albums = albums; 
      [self.tableView reloadData]; 
     }]; 

此时的每张专辑,我需要得到它的封面图片。 专辑对象有一个id字段和一个cover_photo之一。我试图与这两个作为参数的图形查询相同的结果:resultnil

NSDictionary *params = @{ @"type": @"album"};//, @"access_token": [[PFFacebookUtils session] accessToken]}; 

[FBRequestConnection startWithGraphPath: [NSString stringWithFormat:@"/%@/picture", album.coverPath] 
          parameters:params 
          HTTPMethod:@"GET" 
         completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 

          NSString * urlString = [result objectForKey:@"url"]; 
          NSURL *url = [NSURL URLWithString:urlString]; 
          NSURLRequest *request = [NSURLRequest requestWithURL:url]; 

          [cell.imageView setImageWithURLRequest:request 
               placeholderImage:placeholderImage 
                 success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { 

                  weakCell.imageView.image = image; 
                  [weakCell setNeedsLayout]; 

                 } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) { 
                  NSLog(@"%@",error.debugDescription); 
                 }]; 
         }]; 

我在的appdelegate [PFFacebookUtils initializeFacebook];和我有管理是在所有其他palces完美的工作会议。

而这些都是在登录

@[@"user_about_me", @"email", @"user_birthday", @"user_location" ,@"user_friends", @"publish_actions", @"user_photos", @"friends_photos"]

想法,我需要的权限? 也在文档 https://developers.facebook.com/docs/graph-api/reference/v2.3/album/picture 它说使用album-id,但那么cover_photo id是什么?

+1

阅读我的答案...答案为2.4 api ...可能会有所帮助......... http://stackoverflow.com/questions/30207465/ios-facebook-album-photos-picker/ 31789234#31789234 –

回答

2

这有点奇怪,但是当我在图API API浏览器中尝试/<id>/picture时,它会自动将?redirect=false附加到请求中。和你的情况类似,当我从Objective-C对这个边进行Graph API调用时,它给了我null。因此,从图形API浏览器得到一个提示,我尝试将这个参数附加到我的请求中,这实际上使它工作。尝试添加它,看看它是否工作。所以,你的情况:

[NSString stringWithFormat:@"/%@/picture?redirect=false", album.coverPath] 

响应看起来是这样的:

{ 
    data =  { 
     "is_silhouette" = 0; 
     url = "https://fbcdn-sphotos-f-a.akamaihd.net/hphotos..."; 
    }; 
} 

您可以从这里dataurl领域这应该给你的封面照片。

相关问题