Get and show images from Facebook in iOS app

I'm developing a iOS app for iPad. I've implemented Instagram API so I can get and use the photos from the user. Can I do the same but with Facebook? Is there any way to access to users' pictures? Thanks

Answers


The Graph API is where you want to start to see what data you're looking for. For user photos, check out: Albums user has created - https://developers.facebook.com/docs/reference/api/user/ Info about a photo - https://developers.facebook.com/docs/reference/api/photo/

I recommend trying different queries using the Graph API explorer: https://developers.facebook.com/tools/explorer First make sure you ask for user_photos permission Entering me/albums in the query gives you a list of albums for the logged in user. Click on an album's ID in the results to see the info for that album. Enter /photos to see photos for that album.

Once you know what you want you can take a look at the iOS SDKs that are built on top of the Graph API and other APIs to authenticate and for what you're interested in, to grab photos.

For iOS SDK info on making requests, see: https://developers.facebook.com/docs/reference/ios/3.1/class/FBRequestConnection#startWithGraphPath%3AcompletionHandler%3A

So if you want to see say the photos for one album, given an album_id, you would use request code like:

[FBRequestConnection startWithGraphPath:@"<album_id>/photos" 
    completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
       if (!error) {
           NSLog("Results: %@", result);
       }
    }
];

Make sure you've asked for user_photos permissions first.


- (IBAction)btnFBTap:(id)sender {
    [FBSDKProfile enableUpdatesOnAccessTokenChange:YES];
    if ([FBSDKAccessToken currentAccessToken]) {
        [self FBLogin];
    } else  {

        FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
        [login
         logInWithReadPermissions: @[@"public_profile", @"user_photos"]
         fromViewController:self
         handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
             if (error) {
                 // Process error
             } else if (result.isCancelled) {
                 // Handle cancellations
             } else {
                 [self FBLogin];
                 // If you ask for multiple permissions at once, you
                 // should check if specific permissions missing
             }
         }];
    }
}

- (void)FBLogin {

    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me"
                                       parameters:@{@"fields":@"id"}]
     startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
         [[MDManager sharedInstance].loadingView hide];
         if (!error) {
             NSLog(@"fetched user:%@", result);

             // For more complex open graph stories, use `FBSDKShareAPI`
             // with `FBSDKShareOpenGraphContent`
             /* make the API call */
             FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                           initWithGraphPath:[NSString stringWithFormat:@"/%@/photos", result[@"id"]]
                                           parameters:@{@"type":@"uploaded",
                                                        @"fields":@"link,height,width"}
                                           HTTPMethod:@"GET"];
             [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                                   id result,
                                                   NSError *error) {
                 NSLog(@"%@",result); // Return uploaded photos

             }];
         }
     }];
}

Need Your Help

Difference between graph database: Neo4j & AllegroGraph

nosql neo4j social-graph allegrograph

What is the difference between these two graph databases: Neo4j and AllegroGraph? Which is better for Java Web programming?