iOS - Facebook API - 获取用户名的权限

时间:2014-05-06 21:42:19

标签: ios facebook api username

这是我的代码:

  NSArray *permissions = @[@"read_friendlists", @"email",@"user_about_me",@"user_status"];

    // OPEN Session!
    [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:^(FBSession *session,
                                                      FBSessionState status,
                                                      NSError *error) {
                                      // if login fails for any reason, we alert
                                      if (error) {

                                          //NSLog(@"error %@",error);
                                          // show error to user.

                                      } else if (FB_ISSESSIONOPENWITHSTATE(status)) {

                                          // no error, so we proceed with requesting user details of current facebook session.
                                          //NSLog(@"we are here");
                                          //NSLog(@"----%@",[session accessTokenData].accessToken);

                                          NSString *tok = [session accessTokenData].accessToken;
                                          NSLog(@"tok 2");



                                          [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
                                              if (error) {

                                                  NSLog(@"error:%@",error);


                                              }
                                              else
                                              {
                                                  NSLog(@"all dat %@",user);
                                                  // retrive user's details at here as shown below
                                                  NSLog(@"FB user first name:%@",user.first_name);
                                                  NSLog(@"FB user last name:%@",user.last_name);
                                                  NSLog(@"FB user birthday:%@",user.birthday);
                                                  NSLog(@"FB user location:%@",user.location);
                                                  NSLog(@"FB user username:%@",user.username);
                                                  NSLog(@"FB user gender:%@",[user objectForKey:@"gender"]);
                                                  NSLog(@"email id:%@",[user objectForKey:@"email"]);
                                                  NSLog(@"location:%@", [NSString stringWithFormat:@"Location: %@\n\n",
                                                                         user.location[@"name"]]);

                                              }
                                          }];



                                          // [self promptUserWithAccountName];   // a custom method - see below:
                                      }




                                  }];
}

它似乎工作除了&#34;用户名&#34;这是代码中最重要的部分!我错过了什么吗?我尝试了很多权限,但没有提供用户名。我总是没事。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

如果您使用的是最新版本的iOS SDK,那么您将会使用Graph API的v2.0。 {API}的v2.0中已弃用username