我遵循了许多示例并查看了有关此访问令牌错误的许多问题,但我似乎无法找出我得到它的原因或如何修复它。
我像在 3.1 sdk 示例中那样初始化 Facebook:
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, id result, 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
我必须在设置或其他东西中遗漏一些小细节。
谢谢大家!