gpt4 book ai didi

ios - Facebook iOS SDK : get album's cover picture

转载 作者:行者123 更新时间:2023-11-28 21:47:06 25 4
gpt4 key购买 nike

我正在使用包含 Parse 的 Facebook 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 字段。我已经尝试将两者作为图形查询的参数,结果相同:result is nil

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]; 我在那里管理在所有其他地方都完美运行的 session 。

这些是我在登录时需要的权限

@[@"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它说要使用相册 ID,但封面照片 ID 的用途是什么?

最佳答案

这有点奇怪,但当我尝试时 /<id>/picture在图形 API 资源管理器中,它会自动附加 ?redirect=false到请求。与您的情况类似,当我从 Objective-C 调用此边缘的图形 API 时,它给了我 null .因此,从图形 API 资源管理器获得提示后,我尝试将此参数附加到我的请求中,这实际上使它起作用了。尝试添加它,看看它是否有效。所以,在你的情况下:

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

响应看起来像这样:

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

您可以获取 url来自 data 的字段这里应该给你封面照片。

关于ios - Facebook iOS SDK : get album's cover picture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29695903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com