Facebook Graph API - 获取相册ID [英] Facebook Graph API - get a photos album ID
问题描述
我的问题是:如何获取照片上传到的相册ID ?
当我 GET
照片信息相册不存在于我的希望的JSON。
这个问题一直在追赶我一段时间,但我认为我已经破解了坚果。
专辑ID被隐藏在链接值中,因此如果您有Graph API中的照片文本对象,则可以如下检索相册ID:
NSString * link = [item valueForKey:@link];
NSString * album_id = nil;
NSRange fRange = [link rangeOfString:@set = a。];
if(fRange.location!= NSNotFound){
NSInteger firstPos = fRange.location + 6;
NSInteger endPos = [link rangeOfString:@。选项:NSLiteralSearch范围:NSMakeRange(firstPos,25)]。
album_id = [[link substringWithRange:NSMakeRange(firstPos,endPos - firstPos)] copy];
}
它可能都被删除到一行代码,但我认为这更可读。
获取相册信息使用:
[facebook requestWithGraphPath:album_id andDelegate:delegate];
为了让相册中的所有照片使用:
[facebook requestWithGraphPath:[NSString stringWithFormat:@%@ / photos,album_id] andDelegate:delegate];
希望这可以帮助某人。
I'm writing an application that uploads a photo to facebook. I'm not supplying an album ID so an album is created on behalf of my app.
My question is: how do I get the album ID the photo was uploaded to?
When I GET
the the photo information the album isn't present in the JSON which was my hope.
This issue has been bugging me for a while as well, but I think I have cracked the nut.
The album ID is hidden in the link value, so if you have a photo-post object from the Graph API, you can retrieve the Album ID like this:
NSString *link = [item valueForKey:@"link"];
NSString *album_id = nil;
NSRange fRange = [link rangeOfString:@"set=a."];
if(fRange.location != NSNotFound) {
NSInteger firstPos = fRange.location + 6;
NSInteger endPos = [link rangeOfString:@"." options:NSLiteralSearch range:NSMakeRange(firstPos, 25)].location;
album_id = [[link substringWithRange:NSMakeRange(firstPos, endPos - firstPos)] copy];
}
It could probably all be stripped down to one line of code, but I think this is more readable. For getting the album information use:
[facebook requestWithGraphPath:album_id andDelegate:delegate];
For getting all the photos in an album use:
[facebook requestWithGraphPath:[NSString stringWithFormat:@"%@/photos", album_id] andDelegate:delegate];
Hope this can help someone.
这篇关于Facebook Graph API - 获取相册ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!