从Facebook iOS 7获取用户名和个人资料照片 [英] Getting username and profile picture from Facebook iOS 7

查看:81
本文介绍了从Facebook iOS 7获取用户名和个人资料照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多关于从Facebook获取信息的教程,但是迄今为止我已经失败了。我只想从Facebook获取用户名和个人资料照片。

I have read a lot of tutorials about getting information from Facebook, but I have failed so far. I just want to get username and profile picture from Facebook.

- (IBAction)login:(id)sender {

   [FBSession openActiveSessionWithReadPermissions:@[@"email",@"user_location",@"user_birthday",@"user_hometown"]
                                   allowLoginUI:YES
                              completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {

   switch (state) {
      case FBSessionStateOpen:
         [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
            if (error) {
               NSLog(@"error:%@",error);
            } else {
               // 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"]]);

             }
        }];
        break;
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
           [FBSession.activeSession closeAndClearTokenInformation];
        break;
        default:
        break;
       }

   } ];


 }

我用这个代码获取信息,但我无法得到任何信息。你可以帮我吗?或者你可以更喜欢教程阅读吗?我读了developer.facebook.com上的教程。

I used this code for get information, but I cannot get the any information. Can you help me about it? or Can you prefer a tutorial to read it? I have read tutorials on developer.facebook.com.

感谢您的关注。

推荐答案

这是我找到获取用户个人资料照片的最简单的方法。

This is the simplest way I've found to get the user's profile picture.

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

    else {
      NSString *userName = [FBuser name];
      NSString *userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [FBuser objectID]];
    }
  }];

可以使用的其他查询参数是:

Other query parameters that can be used are:


  • 类型:小,正常,大,平方

  • 宽度值>

  • 高度:<值>

    • 同时使用宽度高度来获取裁剪的方面填充图像

    • type: small, normal, large, square
    • width: < value >
    • height: < value >
      • Use both width and height to get a cropped, aspect fill image

      这篇关于从Facebook iOS 7获取用户名和个人资料照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆