Bharathi
Bharathi

Reputation: 485

Facebook API for IOS

I am including Facebook API for IOS in my app to share the link from my app in facebook. When I click "Share" from my app, It shares the link when I already logged in facebook in my device. If not it asks me to login. Once I logged in, the window closed and its not shared that link. i need to click "Share" again to share link. What should I need to share automatically after I logged in. Pls Help me.

Upvotes: 0

Views: 1449

Answers (3)

peterept
peterept

Reputation: 4427

If your app is not re-launching your app after sign-in (from browser or if the user has installed the Facebook app) then you have not added your FB App Id to your Info.plist (which is how your app gets launched)

See the documentation here go to section Modify the app property list file:

... Create a new row named URL types with a single item, URL Schemes, containing a single value, fbYOUR_APP_ID (the literal characters fb followed by your app ID). The following shows exactly how the row should appear in the .plist file...

Eg:

URL Types.[0].URL Schemes.[0].fb1234 (where your Facebook app id is 1234)

Upvotes: 1

Dinesh Raja
Dinesh Raja

Reputation: 8501

See my question if you have any doubt with facebook API integration.

Facebook API dialog page showing error in second time and after that

Try this code:

-(void)buttonPressed:(id)sender{
facebook = [[Facebook alloc] initWithAppId:@"YOUR_APP_ID" andDelegate:self];

 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
            facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
            facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
        }
if (![facebook isSessionValid]) {
    [facebook authorize:nil];
}else{
[self postWall];
}
// Pre 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [facebook handleOpenURL:url]; 
}
- (void)fbDidLogin {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
    [self postWall];
}
-(void)postWall{

    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                            @"https://developers.facebook.com/docs/reference/dialogs/",@"link",
                                   @"http://fbrell.com/f8.jpg",@"picture",
                                   @"Facebook Dialogs",@"name",
                                   @"Reference Documentation",@"caption",
                                   @"Using Dialogs to interact with users.",@"description",
                                   @"Facebook Dialogs are so easy!",@"message",
                                   nil];

    [[self facebook] dialog:@"feed" andParams:params andDelegate:self];

}

Upvotes: 1

Rob
Rob

Reputation: 437412

Did you use the Facebook SDK for iOS (https://developers.facebook.com/docs/mobile/ios/build/)? I scrupulously followed those instructions and it worked well for me on the first try. The only trick for me was the much discussed solution to make sure the app didn't launch Safari for authentication when people didn't have the Facebook app by replacing:

[self authorizeWithFBAppAuth:YES safariAuth:YES];

with

[self authorizeWithFBAppAuth:YES safariAuth:NO];

in the (void)authorize:(NSArray *)permissions method in Facebook.h. But other than that, I just followed the instructions on that above web site and it worked seamlessly for me.

If this doesn't answer your question, perhaps you can post some code so we can help diagnose what's going on. The question (in the absence of code) is a little ambiguous.

Upvotes: 1

Related Questions