在 Facebook iOS SDK 3.5.x 中获取 Facebook 页面访问令牌
Posted
技术标签:
【中文标题】在 Facebook iOS SDK 3.5.x 中获取 Facebook 页面访问令牌【英文标题】:Obtaining Facebook Page Access Token in Facebook iOS SDK 3.5.x 【发布时间】:2013-06-27 04:10:21 【问题描述】:我有一个 Facebook 页面,我是管理员。我已登录 Facebook 并获得了FBSession.actionSession
。即isOpen = YES
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"access_token", @"fields",
nil];
FBRequest *req = [FBRequest requestWithGraphpath:myPageID parameters:params HTTPMethod:@"POST"];
[req startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
dispatch_async(dispatch_get_main_queue(), ^
NSLog(@"Result: %@", result);
);
];
但我在result
中得到了nil
。我知道我必须添加manage_pages
权限,但是在哪里添加呢?
注意:我使用的是 Facebook SDK 3.5.3
来自调试日志的附加信息:
2013-06-27 12:18:34.722 TestFBPostPage[13224:19a03] FBSDKLog: Request <#1113>:
URL: https://graph.facebook.com/MY_PAGE_ID?sdk=ios&fields=access_token&migration_bundle=fbsdk%3A20130409&format=json&access_token=ACCESS_TOKEN_REMOVED
Method: POST
UserAgent: FBiOSSDK.3.5.3
MIME: multipart/form-data; boundary=3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f
Attachments:
sdk: ios
fields: access_token
migration_bundle: fbsdk:20130409
format: json
access_token: ACCESS_TOKEN_REMOVED
2013-06-27 12:18:34.952 TestFBPostPage[13224:19a03] FBSDKLog: Error: HTTP status code: 403
2013-06-27 12:18:34.954 TestFBPostPage[13224:19a03] FBSDKLog: Response <#1113> <Error>:
The operation couldn’t be completed. (com.facebook.sdk error 5.)
【问题讨论】:
我也遇到了这个问题。 【参考方案1】:嗯,这是 SDK 4.x,但这是我让它工作的东西
__block NSString *pageToken;
FBSDKGraphRequest *newRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:[NSString stringWithFormat:@"/%@/accounts", [FBSDKAccessToken currentAccessToken].userID] parameters:nil HTTPMethod:@"GET"];
[newRequest startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
if (error)
NSLog([error localizedDescription]);
else
//here you made need to do some debugging. not sure how it works with multiple pages
pageToken = [[[result objectForKey:@"data"] objectAtIndex:0] objectForKey:@"access_token"];
];
同样,不完全确定当用户是多个页面的管理员时它是如何工作的,但是对于单页面管理员来说,这就是我要做的工作
【讨论】:
以上是关于在 Facebook iOS SDK 3.5.x 中获取 Facebook 页面访问令牌的主要内容,如果未能解决你的问题,请参考以下文章
Facebook SDK:在IOS7上无法完成操作(com.facebook.sdk错误2)
Facebook iOS SDK 返回错误“com.facebook.sdk 错误 4”
Facebook SDK 错误 Domain=com.facebook.sdk Code=5 在 ios 中获取好友列表时
无法在 Xcode 3.2.6 上为 iOS 构建 Facebook SDK