少し遅れているかもしれませんが、これは誰かの役に立つかもしれません。以下は、gplusユーザープロファイルを取得するために私が書いた作業コードです
マークアップの下の HTML では、Google サインイン ボタンが表示されます
<span id="signinButton">
<span
class="g-signin"
data-callback="signinCallback"
data-clientid="YOUR GPLUS CLIENT ID"
data-cookiepolicy="single_host_origin"
data-scope="email">
</span>
</span>
以下はJavaスクリプトです
var access_token;
/**
* Called when the Google+ client library reports authorization status.
*/
function signinCallback(authResult) {
access_token = authResult.access_token;
gapi.client.load('plus', 'v1', function () {
gapi.client.plus.people.get({ userId: 'me' }).execute(printProfile);
});
}
/**
* Response callback for when the API client receives a response.
*
* @param resp The API response object with the user email and profile information.
*/
function printProfile(resp) {
if (resp.code != 403) {
console.log('name:' + access_token.givenname);
console.log('last name:' + access_token.lastname);
console.log('email:' + access_token.emails[0]);
console.log('gender:' + access_token.gender);
console.log('profile image url:' + access_token.image.url);
}
}
以下のように、body タグ内で非同期に Google API JavaScript をロードしていることを確認してください。
<script type="text/javascript">
(function () {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/platform.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
ログアウトを処理するには、以下のリンクで提供する回答を参照してください。ログアウト呼び出し中にこれが使用されるように、バックエンドにaccess_tokenを保存する必要があります。
); 働いていない