Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
May 22, 2010
861
9
Tokyo, Japan
In my App, when user select a item in Table view, my App will check if Facebook in login status.

If already login to Facebook, my app will post item to Facebook wall.

If not loin to Facebook, Facebook login screen will be shown, after login to Facebook, control will return to my app, but user has to select item again to post to Facebook wall.

In this case, How can my app post to wall after login to Facebook without select item again?
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
Sharing the code you've written so far in an attempt to implement this would help us help you...
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
861
9
Tokyo, Japan
Sharing the code you've written so far in an attempt to implement this would help us help you...
Here is my code when user selects a item, do you have any idea?

Code:
-(void)postToFacebook {    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }

    if (![facebook isSessionValid]) {
        NSArray *permissions =  [NSArray arrayWithObjects:@"read_stream", @"publish_stream", nil];
        [facebook authorize:permissions];
    }
    
    NSString *title = [self event];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   title,  @"message",
                                   nil];
    
    [facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
}
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
I'm not familiar with Facebook's graph APIs, but I would guess that

Code:
[facebook authorize:permissions];

will have some kind of callback it will send to a delegate as soon as the user successfully logs on. When your delegate receives the callback, make the attempt to post to the user's wall again.
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
861
9
Tokyo, Japan
I'm not familiar with Facebook's graph APIs, but I would guess that

Code:
[facebook authorize:permissions];

will have some kind of callback it will send to a delegate as soon as the user successfully logs on. When your delegate receives the callback, make the attempt to post to the user's wall again.
That is what I want to know, the callback is as below, I don't know how to post again!
Code:
// Pre 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [detailViewController.facebook handleOpenURL:url]; 
}

// For 4.2+ support
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [detailViewController.facebook handleOpenURL:url]; 
}
 

sundialsoft

macrumors regular
Sep 2, 2010
169
63
Scotland
Facebook - posting after login

At the point where your user first makes a selection you can save the selection either as global variables (say in your app delegate) or in nsuserdefaults.
Once the login is complete you just do a facebook post with the saved data. It's really simple. If you can do one post with data you can do the same thing later after the login with the same data so long as you have preserved it.

I assume you are using the latest FBConnect which is well documented & easier to follow than earlier versions.

I'm very familiar with Facebook posts so can assist if you are still stuck.
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
861
9
Tokyo, Japan
At the point where your user first makes a selection you can save the selection either as global variables (say in your app delegate) or in nsuserdefaults.
Once the login is complete you just do a facebook post with the saved data. It's really simple. If you can do one post with data you can do the same thing later after the login with the same data so long as you have preserved it.

I assume you are using the latest FBConnect which is well documented & easier to follow than earlier versions.

I'm very familiar with Facebook posts so can assist if you are still stuck.
Thanks for your suggestion. i already got what I need as below,
Code:
-(void)postToFacebook { 
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }

    if (![facebook isSessionValid]) {
        // save IndexPath to use next time 
        NSArray *permissions = *[NSArray arrayWithObjects:@"read_stream", @"publish_stream", nil];
        [facebook authorize:permissions];
    }
    else {
       NSString *title = [self event];// use IndexPath in this method
       NSMutableDictionary *params = = [NSMutableDictionary dictionaryWithObjectsAndKeys:title,  @"message", nil];

       [facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
    }
}
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.