简体   繁体   English

我想制作使用Facebook凭据登录我的应用程序的iPhone应用程序

[英]I want make iphone app that uses Facebook credentials to login to my app

I have used following code 我使用了以下代码

facebook = [[Facebook alloc] initWithAppId:APPLICATION_ID];
    facebook.accessToken    = [[NSUserDefaults standardUserDefaults] stringForKey:@"AccessToken"];
    facebook.expirationDate = (NSDate *) [[NSUserDefaults standardUserDefaults] objectForKey:@"ExpirationDate"];

NSArray * _permissions =  [[NSArray arrayWithObjects: @"read_stream",@"user_about_me",nil] retain];

if ([facebook isSessionValid] == NO) 
{
    [facebook authorize:_permissions delegate:self];
}
[facebook requestWithGraphPath:@"me" andDelegate:self];

i want to acess user profile information. 我想获取用户个人资料信息。 but i am getting following error message. 但我收到以下错误消息。

 REsult:Error Domain=facebookErrDomain Code=10000 "The operation couldn’t be completed. (facebookErrDomain error 10000.)" UserInfo=0x6d41090 {error=<CFBasicHash 0x6d91570 [0x2b4a380]>{type = mutable dict, count = 2,
entries =>
    2 : <CFString 0x6d8c990 [0x2b4a380]>{contents = "type"} = <CFString 0x6d1af30 [0x2b4a380]>{contents = "OAuthException"}
    3 : <CFString 0x6d91b90 [0x2b4a380]>{contents = "message"} = <CFString 0x6d3a000 [0x2b4a380]>{contents = "An active access token must be used to query information about the current user."}

can any help me ?i am new to iphone development. 可以帮助我吗?我是iphone开发的新手。

thanks you in advance. 提前谢谢你。

You can't request information from Facebook until the authorization process is complete. 在授权过程完成之前,您无法从Facebook请求信息。 When you call authorize, it only starts the autorization process (it is asynchronous). 当您调用authorize时,它只会启动自动化过程(它是异步的)。 You have to implement FBSessionDelegate to listen for when the fbDidLogin method is called. 您必须实现FBSessionDelegate以侦听何时调用fbDidLogin方法。 Only then can you perform requests on the data. 只有这样才能对数据执行请求。

One option would be to create a controller that wraps around the Facebook class and pass in a completion block that will be called once the user has completed the authorization process. 一种选择是创建一个包裹Facebook类的控制器,并传入一个完成块,一旦用户完成授权过程就会调用该完成块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM