开发者

Can't get user info from Facebook with OAuth 2.0

As soon as the user is logged in, I retrieve the user info using this code:

[_facebook requestWithGraphPath:@"me" andDelegate:self];

It worked for the first few times, but it eventually returned an error. I thought it was a session thing since I have "offline_access" on my permissions.开发者_如何学运维 I logged out from Facebook and compiled again from a clean build and it still returns this error:

Error Domain=facebookErrDomain Code=10000 UserInfo=0x54a2930 "Operation could not be completed. (facebookErrDomain error 10000.)"

I'm assuming my access token is valid since I can do posting. Am I right to assume that?

I also noticed that whenever I log in, Facebook doesn't redirect me to ask permission if I allow my app to access my user info.

Can anyone tell me what's wrong?


Answer on authorize command seems to be different. Now, there's no expiration date as it was before. I tried with forcing isSessionValid to return TRUE, and it works.

isSessionValid checks accessToken AND expirationDate. As there's no expiration date, the function return FALSE.

Don't know if it's a temporary modification from facebook, or definitive one. In this case, SDK must be fixed, I presume. And a new call must retrieve expirationDate.


Here's a temporary fix I've used. You can find this method line 46 in FBLoginDialog.m

- (void) dialogDidSucceed:(NSURL*)url {
  NSString *q = [url absoluteString];
  NSString *token = [self getStringFromUrl:q needle:@"access_token="];
  NSDate *expirationDate = [NSDate distantFuture];

  if ((token == (NSString *) [NSNull null]) || (token.length ==0)) {
    [self dialogDidCancel:url];
    [self dismissWithSuccess:NO animated:YES];
  } else {
    if ([_loginDelegate respondsToSelector:@selector(fbDialogLogin:expirationDate:)]) {
      [_loginDelegate fbDialogLogin:token expirationDate:expirationDate];
    }
    [self dismissWithSuccess:YES animated:YES];
  }
}

Does everyone with this issue request the offline_access permission? It's the only reason I can see an expiration date not being sent. Maybe try not requestion the offline_access permission.


I've had same problem. I checked my privacy settings,permissions,other method etc..., but I couldn't solve it. Many sites said "check permission for accessing to offline_access/read_stream/publish_stream",I think these are important too,but I couldn't fix it.

Then I found following solution finally, it works fine.

You should change "safariAuth:YES" to "safariAuth:NO" on "Facebook.m" file.

- (void)authorize:(NSArray *)permissions
         delegate:(id<FBSessionDelegate>)delegate {
            [_permissions release];
            _permissions = [permissions retain];
            _sessionDelegate = delegate;

            //[self authorizeWithFBAppAuth:YES safariAuth:YES];
            //You can get auth_token in iOS App!
           [self authorizeWithFBAppAuth:YES safariAuth:NO];      
}

Then you can use following method to get your own info if you are logged in.

[facebook requestWithGraphPath:@"me" andDelegate:self];

if you are not logged in, You should login by following method first.

permissions =  [[NSArray arrayWithObjects:
             @"email", @"read_stream", @"user_birthday", 
             @"user_about_me", @"publish_stream", @"offline_access", nil] retain];
if (![facebook isSessionValid]) {
    [facebook authorize:permissions delegate:self];
}

Following post saved me.Thank you so much! How to retrieve Facebook response using Facebook iOS SDK

Good Luck & Happy-coding! Thank you.


I've had this problem, mainly because my Facebook account has is maxed on privacy.

It's most likely the permissions that you passed in during login. BY default it will only give access to public info. Remember there is less and less info that is public in Facebook.

Try changing your permission to something like "read_stream",nil

Then instead of [_facebook requestWithGraphPath:@"me" andDelegate:self];

Try using [_facebook requestWithGraphPath:@"me/home" andDelegate:self];

This should return your news feed. Worked for me 5 mins ago.


Not much to add here, doesn't work here too. I use the iOS SDK to post to the stream and it worked until yesterday. Today my client called me and complained. Ugh.

I have requested the offline access permission and of course the "publish_stream" permission...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜