填充用户详细信息facebook

时间:2014-01-26 14:02:41

标签: ios objective-c facebook

我正在尝试从我的应用中登录的会话用户填充用户详细信息。问题是它似乎触发了错误消息而不是:

NSLog(@"%@", user.name);
NSLog(@"%@", [user objectForKey:@"id"]);

当我删除

if (!error) { }

它给我的代码回答(null)(null)

我的问题是为什么它返回null而不是user.name和user.id ??

appdelegate.m

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {


        return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication fallbackHandler:^(FBAppCall *call) {

        if (call.accessTokenData) {
            if ([FBSession activeSession].isOpen) {
                NSLog(@"INFO: Ignoring app link because current session is open.");
            }
            else {
                [self handleAppLink:call.accessTokenData];
            }
        }
    }];
}

LoginViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self updateView];

    AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
    if (!appDelegate.session.isOpen) {
        // create a fresh session object
        appDelegate.session = [[FBSession alloc] init];


    if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {

            [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                         FBSessionState status,
                                                         NSError *error) {
                // we recurse here, in order to update buttons and labels
                [self updateView];

            }];
        }

    }

    [self populateUserDetails];

}

- (void)populateUserDetails {
            AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
        if (appDelegate.session.isOpen) {
            [[FBRequest requestForMe] startWithCompletionHandler:
             ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
                 if (!error) {
                     NSLog(@"%@", user.name);
                     NSLog(@"%@", [user objectForKey:@"id"]);
                 }
             }];

    }
}

错误消息:

Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xc87b9f0 {com.facebook.sdk:ParsedJSONResponseKey={
    body =     {
        error =         {
            code = 2500;
            message = "An active access token must be used to query information about the current user.";
            type = OAuthException;
        };
    };
    code = 400;
}, com.facebook.sdk:HTTPStatusCode=400}
2014-01-26 15:09:49.486 Friendflirt[1125:70b]

0 个答案:

没有答案