Search code examples
iosfacebookfacebook-graph-apioauth-2.0facebook-ios-sdk

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?


Solution

  • 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.