Reputation: 131
I downloaded the Facebook iPhone demo app recently. I have made several attempts to grasp the authentication process and I'm totally confused. There seems to be a lot of sample code out there that has been rendered obsolete in this version of the API.
In the .m file for my primary view controller, I have the following at the start:
#import "FBConnect.h"
The button that requires information from Facebook uses this line, unchanged from the demo app:
[_facebook requestWithGraphPath:@"me" andDelegate:self];
This calls the following method:
- (void)request:(FBRequest *)request didLoad:(id)result {
I have hacked my functionality into this method. I pull a few things I need from Facebook and send them to my backend in a HTTP POST command. For example, [result objectForKey:@"id"] returns the id and [result objectForKey:@"name"] returns the name. However, [result objectForKey:@"access_token"] returns nothing. This is very frustrating because I need to pass the access token to my Google App Engine user management back end to create a new user. So, hopefully the code I have included makes my authetication strategy clear (whatever it is). Does anyone know how I can get the access token in this context? I would appreciate it if you could help me out with what header files I need to have included etc. ?
Thanks,
John
Upvotes: 2
Views: 1602
Reputation: 1918
after success full login you can retrieve using,
[[FBSession activeSession] accessToken];
Upvotes: 1
Reputation: 6667
I'm doing the same exact thing you are. I'm making my own HTTP requests, so I need the accessToken, and what's more, the iOS Facebook SDK doesn't remember the accessToken past launches, even with a no-expire request!
After calling [_facebook authorize:permissions delegate:self]; In the fbDidLogin delegate call, you can easily pull (assuming you have the facebook object retained in _facebook):
- (void)fbDidLogin {
NSString *accessToken = _facebook.accessToken;
NSDate *expirationDate = _facebook.expirationDate;
}
Voilà.
To handle persistence through app launches, you can save this data and manually set those accessors prior to any requests.
Upvotes: 3