在Facebook iOS SDK 3.5.x中获取Facebook页面访问令牌

时间:2013-06-27 04:10:22

标签: facebook-ios-sdk

我有一个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);
        });
    }];

但我在nil获得了result。我知道我必须添加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 个答案:

答案 0 :(得分:0)

嗯,这是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"];


        }];

同样,当用户管理多个页面时,不完全确定它是如何工作的,但是对于单页面管理员来说,这就是我要工作的方式