获取个人资料信息

使用默认范围将用户登录到 Google 后,您可以访问用户的 Google ID、姓名、个人资料网址和电子邮件地址。

如需检索用户的个人资料信息,请使用 getBasicProfile() 方法。例如:

// auth2 is initialized with gapi.auth2.init() and a user is signed in.

if (auth2.isSignedIn.get()) {
  var profile = auth2.currentUser.get().getBasicProfile();
  console.log('ID: ' + profile.getId());
  console.log('Full Name: ' + profile.getName());
  console.log('Given Name: ' + profile.getGivenName());
  console.log('Family Name: ' + profile.getFamilyName());
  console.log('Image URL: ' + profile.getImageUrl());
  console.log('Email: ' + profile.getEmail());
}