使用外部服务登录Meteor:如何获取个人资料信息?

GG.*_*GG. 3 twitter facebook login github meteor

我使用Accounts-UI和Accounts- [Github/Twitter/Facebook/Google]软件包,允许使用外部服务登录.

我修改Accounts.ui.configrequestPermissions,例如:

Accounts.ui.config({
  requestPermissions: {
    github: ['user'],
    facebook: ['user_photos']
  }
});
Run Code Online (Sandbox Code Playgroud)

但是当我用Github(例如)登录我时,我只得到了我的Github的名字.

与其他外部服务相同的事情.

如何获取更多信息,例如个人资料图片的网址?

cma*_*her 14

您可以使用Accounts.onCreateUser(fn)方法自定义创建用户时存储的内容.以下是一些示例代码:

Accounts.onCreateUser(function (options, user) {
  var accessToken = user.services.github.accessToken,
      result,
      profile;

  result = Meteor.http.get("https://api.github.com/user", {
    params: {
      access_token: accessToken
    }
  });

  if (result.error)
    throw result.error;

  profile = _.pick(result.data,
    "login",
    "name",
    "avatar_url",
    "url",
    "company",
    "blog",
    "location",
    "email",
    "bio",
    "html_url");

  user.profile = profile;

  return user;
});
Run Code Online (Sandbox Code Playgroud)

您必须在回调函数中对服务进行额外调用以获取任何其他属性.目前,我无法直接插入Meteor用于获取身份属性的方法.

  • 另外,我在这里做了一个截屏视频:http://www.eventedmind.com/posts/meteor-customizing-login (2认同)