PDA

View Full Version : How to redo action before Login to Facebook?




mikezang
Mar 12, 2012, 07:36 AM
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
Mar 12, 2012, 08:19 AM
Sharing the code you've written so far in an attempt to implement this would help us help you...

mikezang
Mar 12, 2012, 08:44 AM
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?

-(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
Mar 12, 2012, 09:45 AM
I'm not familiar with Facebook's graph APIs, but I would guess that

[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
Mar 12, 2012, 09:50 AM
I'm not familiar with Facebook's graph APIs, but I would guess that

[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!
// 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
Mar 16, 2012, 02:19 PM
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
Mar 16, 2012, 07:34 PM
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,

-(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];
}
}