English 中文(简体)
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?

最佳回答

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.

问题回答

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.

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





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签