问题
I am developing a iPhone application which get facebook album with this URL https://graph.facebook.com/me/albums?access_token=2227470867|2.ZJr73vaEvFeN4fI_A70RFw__.3600.1297090800-100000566543036|WmgxdwULBgKXl8J7ksGIA1tyGik
Now i want to get photos from this album.
Any Idea will be appreciated.
Thanks in Advance.
回答1:
So /me/albums returns an array of Album objects, each of which has an id
.
If an album had an id of 99394368305, you can go to
https://graph.facebook.com/99394368305/photos
to get an array of photo objects.
Each of these will have the picture
and source
properties to get the image data from facebook.
They will all have an images
array as well if you want pre-scaled images instead of just the originals.
All the facebook queries give JSON back - I'm assuming that you know how to parse this?
回答2:
It takes lot of time because of following steps;
1) get uid of friend using :
NSString *urlString=[NSString stringWithFormat:@"https://graph.facebook.com/me/friends?access_token=%@&fields=id,picture,name,birthday",fbGraph.accessToken];
2) put friends uid to get album id:
NSString *urlString1=[NSString stringWithFormat:@"https://graph.facebook.com/%@/albums?access_token=%@",obj.uid,fbGraph.accessToken];
NSString *album = [[[_response1 objectForKey:@"data"]objectAtIndex:j]objectForKey:@"name"];
if ([album isEqualToString:@"Profile Pictures"])
{
albumid = [[[_response1 objectForKey:@"data"]objectAtIndex:j]objectForKey:@"id"];
}
3) then put the album id to get the picture from that album:
NSString *albumUrl=[NSString stringWithFormat:@"https://graph.facebook.com/%@/photos?type=album&access_token=%@",albumid,fbGraph.accessToken];
NSString *picUrl=[[[[[_response2 objectForKey:@"data"]objectAtIndex:0]objectForKey:@"images"]objectAtIndex:0]objectForKey:@"source"];
Kindly tell me some other method to get profile picture with large size in a single step to save time.
回答3:
The code below should do the right job for you. It gets albums for logged user and then requests for photos of this albums. In the place where is a comment you will have the access to all photos. For more info you can refer to docs:
FBRequest *request = [FBRequest requestForGraphPath:@"me/albums"];
[request startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary <FBGraphUser> *my, NSError *error) {
if ([my[@"data"]count]) {
for (FBGraphObject *obj in my[@"data"]) {
FBRequest *r = [FBRequest requestForGraphPath:[NSString stringWithFormat:@"/%@/photos", obj[@"id"]]];
[r startWithCompletionHandler:^(FBRequestConnection *c, NSDictionary <FBGraphUser> *m, NSError *err) {
//here you will get pictures for each album
}];
}
}
}];
回答4:
Facebook developers new code:
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"/{user-id}"
parameters:params
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
}];
Latest Facebook Graph API docs
来源:https://stackoverflow.com/questions/4921945/how-to-get-photos-of-a-facebook-album-in-iphone-sdk