我正在开发基于与服务器通信的iPhone应用程序,我想使用Facebook身份验证机制。
基本上,我认为它应该是这样的:
我的问题是:服务器应该如何询问Facebook,给定访问令牌是否有效?我想我应该以某种方式检查一下这个标记对我的Facebook应用程序是否有效。
我已经尝试过很多Facebook查询来绘制API,这是我已经发现的,但没有像我预期的那样起作用。你能给我举个例子吗?
发布于 2013-06-24 06:28:54
我要让accessToken通过这个
NSString * accessToken = [[FBSession activeSession] accessToken];然后,用户可以通过实现以下方法来获取用户的Facebook数据:
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
{
switch (state)
{ /// **************** IT GIVES THIS ACCESS TOKEN *****************/////////////////////////
case FBSessionStateOpen:
{
// https://graph.facebook.com/me?access_token=%@
accessToken = [[FBSession activeSession] accessToken];
NSLog(@"accessToken: %@",accessToken);
NSString *urlList = [NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@",accessToken];
NSURL *url1 = [NSURL URLWithString:urlList];
NSURLRequest *urlReqst = [[NSURLRequest alloc] initWithURL:url1];
NSData *dataConnection = [NSURLConnection sendSynchronousRequest:urlReqst
returningResponse:nil
error:nil];
NSString *jsonData = [[NSString alloc] initWithData:dataConnection
encoding:NSUTF8StringEncoding];
NSDictionary *jsonDic = [jsonData JSONValue];
self.appid = [jsonDic valueForKey:@"id"];
self.appusername = [jsonDic valueForKey:@"username"];
self.appfirst_name = [jsonDic valueForKey:@"first_name"];
self.applast_name = [jsonDic valueForKey:@"last_name"];
self.appname = [jsonDic valueForKey:@"name"];
self.appemailId = [jsonDic valueForKey:@"email"];
[self LoginAPI];
if ([self.navigation.presentedViewController isKindOfClass:[LoginPage class]]) {
[self.navigation.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[self.navigation popToRootViewControllerAnimated:NO];
[self showLoginView];
[self fbDidLogout];
break;
default:
break;
}
if (error)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}为了通过Facebook登录进入应用程序,您可以通过这个样本登录
希望这能帮你..。
https://stackoverflow.com/questions/17268945
复制相似问题