プロフィール情報の取得

デフォルトのスコープを使用して Google でユーザーをログインすると、ユーザーの Google ID、名前、プロフィール URL、メールアドレスにアクセスできます。

ユーザーのプロフィール情報を取得するには、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());
}