无法使用 OAuth 2.0 从 Facebook 获取用户信息

发布于 2024-09-18 13:04:28 字数 454 浏览 8 评论 0原文

用户登录后,我就使用以下代码检索用户信息:

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

它在前几次有效,但最终返回了错误。我认为这是一个会话问题,因为我的权限有“offline_access”。我从 Facebook 注销并从干净的构建中再次编译,但它仍然返回此错误:

错误域=facebookErrDomain代码=10000 UserInfo=0x54a2930“操作无法完成。(facebookErrDomain错误10000。)”

我假设我的访问令牌有效,因为我可以发帖。我的假设正确吗?

我还注意到,每当我登录时,如果我允许我的应用程序访问我的用户信息,Facebook 不会重定向我来请求许可。

谁能告诉我出了什么问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

小情绪 2024-09-25 13:04:28

授权命令的答案似乎不同。现在,不像以前那样没有有效期了。我尝试强制 isSessionValid 返回 TRUE,并且它有效。

isSessionValid 检查 accessToken 和过期日期。由于没有到期日期,该函数返回 FALSE。

不知道这是 Facebook 的临时修改还是最终修改。在这种情况下,我认为 SDK 必须修复。新的调用必须检索expirationDate。

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.

千纸鹤 2024-09-25 13:04:28

这是我使用过的临时修复。您可以在 FBLoginDialog.m 中的第 46 行找到此方法。

- (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];
  }
}

是否每个遇到此问题的人都请求离线访问权限?这是我看到过期日期未发送的唯一原因。也许尝试不请求offline_access 权限。

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.

久夏青 2024-09-25 13:04:28

我也遇到过同样的问题。我检查了我的隐私设置、权限、其他方法等...,但我无法解决它。
很多网站都说“检查访问offline_access/read_stream/publish_stream的权限”,我认为这些也很重要,但我无法修复它。

然后我终于找到了以下解决方案,效果很好。

您应该在“Facebook.m”文件上将“safariAuth:YES”更改为“safariAuth:NO”。

- (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];      
}

如果您已登录,则可以使用以下方法获取自己的信息。

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

如果您未登录,则应先通过以下方法登录。

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];
}

以下帖子救了我。非常感谢!
如何使用 Facebook iOS SDK 检索 Facebook 回复

好运气与快乐编码!
谢谢。

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.

双手揣兜 2024-09-25 13:04:28

我遇到过这个问题,主要是因为我的 Facebook 帐户的隐私权限已达到上限。

这很可能是您在登录期间传入的权限。默认情况下,它只允许访问公共信息。请记住,Facebook 上公开的信息越来越少。

尝试将您的权限更改为“read_stream”,nil

然后而不是 [_facebook requestWithGraphPath:@"me" andDelegate:self];

尝试使用 [_facebook requestWithGraphPath:@"me/home" andDelegate:self];

这应该返回您的新闻提要。
5 分钟前为我工作。

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.

筱果果 2024-09-25 13:04:28

这里没有太多要添加的,在这里也不起作用。我使用 iOS SDK 发布到流,直到昨天才正常。今天我的客户打电话给我抱怨。啊。

我已经请求了离线访问权限,当然还有“publish_stream”权限......

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文