Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS facebook sdk how to download album, profile photos data

I would like to allow my iPhone App users to view and select from their facebook profile photos, download the photo to use as a profile pic. I am currently using the Facebook SSO SDK and successfully logging in and accessing Graph information. Have tried to access photo information (after successful SSO login) using

[facebook requestWithGraphPath:@"me/albums"];

but I just get an empty data object in return. I've tried using the Facebook API explorer, which is very helpful, and it does give me data for /picture and /photos and /albums. For some reason I don't get the same data using requestWithGraphPath with me/albums, me/picture or me/photos. Just plain "me" works fine but doesn't give me any picture info. Can anybody tell me what I'm doing wrong?

Note: this is the API reference: Facebook Graph API

I did get picture profile to work like this:

[facebook requestWithGraphPath:@"me?fields=picture"];

Update: really I want all of the Profile Photos which is a photo album so I need to know how to access albums through iOS. The profile picture I have successfully obtained now.

I have added permissions "user_photos" and "friends_photos" for photo albums according to API:

    NSArray *permissions = [[NSArray alloc] initWithObjects:
                            @"user_likes",
                            @"user_birthday",
                            @"email",
                            @"publish_stream",
                            @"publish_actions",
                            @"user_photos",
                            @"friends_photos",
                            nil];
    [facebook authorize:permissions];

When I say I'm getting empty data, this is the JSON result (in request:didLoad:) that gets returned:

 {
    data =     (
    );
}

From my log file output:

- (void) request:(FBRequest *)request didLoad:(id)result{
    NSLog(@"%@",result);

}

Final Note: What finally worked was to use another device, which updated my permissions and then everything started working! My best guess is that the emulator and my iPhone were not updating my facebook permissions so I was being denied access to photos and getting an empty data array.

This SO question was a big help also: How to get photos of a facebook album in iPhone SDK?

like image 266
Alan Moore Avatar asked Jul 27 '12 15:07

Alan Moore


2 Answers

For the sake of future viewers, I'm putting the answer to my own question since I haven't received a complete answer from anyone else.

First, you must have the right permissions, either "user_photos" or "friends_photos". Then you have to make sure that your test device updates your permissions -- I think restarting the device is what ultimately did it for me.

Once you've done that, you can get the JSON list of albums, after logging in via SSO, using this call:

[facebook requestWithGraphPath:@"me/albums" andDelegate:self];

This will give JSON array (under key data) with all kinds of information about each album, including the ID. To get a list of photos for a particular album ID (say its '123456789') do the following:

NSString * albumId = @"123456789";
NSString * path = [NSString stringWithFormat:@"%@/photos", albumId];
[facebook requestWithGraphPath:path andDelegate:self];

Your response will of course come via the FBRequestDelegate method request:didLoad where you can process the JSON data.

like image 182
Alan Moore Avatar answered Sep 27 '22 23:09

Alan Moore


Download the FBGraph Api documents folder then add it to in your folder. and read the instruction on facebook developer site http://developers.facebook.com/docs/reference/api/.

This is the sample code - sample code

In this you will get a user profile pic in UIAlertView. You can show it where you want.

like image 28
TheTiger Avatar answered Sep 27 '22 21:09

TheTiger