简体   繁体   中英

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.

thanks you in advance.

You can't request information from Facebook until the authorization process is complete. When you call authorize, it only starts the autorization process (it is asynchronous). You have to implement FBSessionDelegate to listen for when the fbDidLogin method is called. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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