How to get the Facebook user id using the access token

后端 未结 8 2400
深忆病人
深忆病人 2020-11-28 02:19

I have a Facebook desktop application and am using the Graph API. I am able to get the access token, but after that is done - I don\'t know how to get the user\'s ID.

<
8条回答
  •  猫巷女王i
    2020-11-28 02:50

    With the newest API, here's the code I used for it

    /*params*/
    NSDictionary *params = @{
                             @"access_token": [[FBSDKAccessToken currentAccessToken] tokenString],
                             @"fields": @"id"
                             };
    /* make the API call */
    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                  initWithGraphPath:@"me"
                                  parameters:params
                                  HTTPMethod:@"GET"];
    
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                          id result,
                                          NSError *error) {
        NSDictionary *res = result;
        //res is a dict that has the key
        NSLog([res objectForKey:@"id"]);
    

提交回复
热议问题