我已经遵循了许多例子,并且看了关于这个访问令牌错误的许多问题,但是我似乎找不到为什么我得到它或如何解决它.
我初始化了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.
当我尝试这个:
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection,id result,NSError *error) { [self showAlert:@"logged in?" result:result error:error]; }];
或这个:
NSMutableDictionary* fbPost = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"post from iOS",@"message",nil]; [FBRequestConnection startWithGraPHPath:@"me/Feed" parameters:fbPost HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection,NSError *error) { [self showAlert:@"message posted?" result:result error:error]; }];
但我得到:
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}}
我已经从我的FBSession采取了访问令牌,并将其放入Facebook的访问令牌调试器中,并显示出我有一个很好的例证:
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
我必须在设置或某些东西中丢失一些小细节.
先谢谢大家!
解决方法
根据文件,https://developers.facebook.com/docs/reference/ios/3.1/class/FBRequestConnection
“请求使用由[FBSession activeSession]表示的活动会话.
这适用于处理请求的静态方法.所以你想做的是确保你设置了活动的会话.执行以下操作:
[FBSession setActiveSession:self.fb];