Question

I have an app setup atm using an email and password login, I'm wondering how I can add a facebook connection between the user's account and facebook just like Instagram. Does it automatically login to facebook everytime? I know you just click facebook when you're uploading a new pic and it posts to fb at the same time.

Was it helpful?

Solution

I believe Instagram currently uses the Facebook SDK for iOS but I would recommend using the Facebook Open Graph API. It's much easier to use and extremely straight forward on calls to get photos, posts, likes, etc.

Here's basically what you need to do:

1.) Import the Social.Framework and Accounts.Framework

2.) Allocate an ACAccountStore

3.) Create an ACAccountType of ACAccountTypeIdentifierFacebook from that ACAccountStore

4.) Create a iOS Facebook ID key on developer.facebook.com

5.) Create a NSMutableDictionary with the initial account permissions and audience types and pass that into requestAccessToAccountsWithType: like so:

NSArray *permissions = @[@"read_stream"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"123456789",ACFacebookAppIdKey,permissions,ACFacebookPermissionsKey,ACFacebookAudienceFriends,ACFacebookAudienceKey, nil];
[accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
    //check for permission granted and errors and ask for more permissions or do whatever requests you want
    }

6.) Once you have your necessary permissions all you have to do is perform SLRequest calls and retrieve the data in the completion handler. Check out the various permission strings and the facebook dev site and you'll be good to go. Hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top