iOS Facebook SDK:必须使用活动的访问令牌来查询有关当前用户的信息 [英] iOS Facebook SDK: An active access token must be used to query information about the current user

查看:155
本文介绍了iOS Facebook SDK:必须使用活动的访问令牌来查询有关当前用户的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经遵循了许多例子,并且看了关于这个访问令牌错误的许多问题,但我似乎找不到为什么我得到它或如何解决它。


$ b $我初始化了Facebook,就像他们在3.1 sdk示例中一样:

  NSArray * permissions = [[NSArray alloc] initWithObjects :@publish_stream,@publish_actions,nil]; 
self.fb = [[FBSession alloc] initWithPermissions:permissions];
[self.fb openWithCompletionHandler:^(FBSession * session,
FBSessionState status,
NSError * error)
{
[self sessionStateChanged:session:status:error] ;
}];

这个工作正常,用户被要求在Safari中接受应用权限,并返回到应用程序之后。当用户返回到应用程序时,我的FBSessionState是FBSessionStateOpen。​​



当我尝试这个:



<$ p $ (FBRequestConnection * connection,id result,NSError * error)
{

[self showAlert:@登录?结果:结果错误:错误];
}];

或此:

  NSMutableDictionary * fbPost = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@从iOS发布,@message,nil]; 
[FBRequestConnection startWithGraphPath:@me / feed参数:fbPost HTTPMethod:@POSTcompletionHandler:^(FBRequestConnection * connection,id result,NSError * error)
{

[self showAlert:@message posted?结果:结果错误:错误];
}];

但我得到:

  FBSDKLog:FBURLConnection<#1126> ;: 

持续时间:936 msec

响应大小:0 kB

MIME类型:text / javascript

响应:

{error:{message:必须使用活动的访问令牌来查询有关当前用户的信息。 ,type:OAuthException,code:2500}}

来自我的FBSession的令牌,并将其放入Facebook的访问令牌调试器中,并显示我有一个很好的例证:

 应用程序ID:隐藏> 
元数据:{sso:iphone-safari}
用户ID:< hidden>
发行:1351525817(约一个小时前)
到期日:1356709817(约2个月)
有效:True
原产地:手机Web Faceweb
范围:create_note photo_upload publish_action publish_stream share_item status_update video_upload

我必须在设置或某些东西中缺少一些小细节。



所有提前谢谢!

解决方案

根据文档, https://developers.facebook.com/docs/reference/ios/3.1/class/FBRequestConnection



请求使用[FBSession activeSession]表示的活动会话。



适用于处理请求的静态方法。所以你想做的是确保你设置了活动的会话。执行以下操作:

  [FBSession setActiveSession:self.fb]; 

在调用第一个FBRequestConnection start *方法之前


I have followed many examples and looked at many questions regarding this access token error, but I can't seem to find out why I am getting it or how to fix it.

I init Facebook like they do in the 3.1 sdk examples:

 NSArray* permissions = [[NSArray alloc] initWithObjects:@"publish_stream", @"publish_actions", nil];
 self.fb = [[FBSession alloc] initWithPermissions:permissions];
 [self.fb openWithCompletionHandler:^(FBSession *session,
                                         FBSessionState status,
                                         NSError *error)
     {
         [self sessionStateChanged:session :status :error];
     }];

This works fine and the user is asked to accept the app permissions in Safari and is returned to the app afterwards. When the user is returned to the app, my FBSessionState is FBSessionStateOpen.

When I try this:

[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
                 {

                     [self showAlert:@"logged in?" result:result error:error];
                 }];

or this:

NSMutableDictionary* fbPost = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"post from iOS", @"message", nil];
[FBRequestConnection startWithGraphPath:@"me/feed" parameters:fbPost HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
                                        {

                                            [self showAlert:@"message posted?" result:result error:error];
                                        }];

but I get:

FBSDKLog: FBURLConnection <#1126>:

  Duration: 936 msec

Response Size: 0 kB

  MIME type: text/javascript

  Response:

{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}

I have taken the access token from my FBSession and put it into Facebook's Access Token Debugger and it shows I have a good token:

App ID: <hidden>
Metadata: {"sso":"iphone-safari"}
User ID: <hidden>
Issued:  1351525817 (about an hour ago)
Expires: 1356709817 (in about 2 months)
Valid:  True
Origin: Mobile Web Faceweb
Scopes: create_note photo_upload publish_actions publish_stream share_item status_update video_upload

I must be missing some small detail in the settings or something.

Thank you all in advance!

解决方案

According to the docs, https://developers.facebook.com/docs/reference/ios/3.1/class/FBRequestConnection

"The request uses the active session represented by [FBSession activeSession]."

This applies to the static methods dealing with requests. So what you want to do is make sure you set the active session. Do the following:

[FBSession setActiveSession:self.fb];

Just before you call the first FBRequestConnection start* method.

这篇关于iOS Facebook SDK:必须使用活动的访问令牌来查询有关当前用户的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆