2016-04-20 11 views
0

JavaスクリプトでJavaスクリプトのonclickイベントを使用しています。ログインユーザーは「結果ステータスがsignedin」の条件になりますが、プロファイルデータ。 api keyとは何かを説明してください、私はクライアントidについて知っていますが、gapi.client.setApiKey()このメソッド内に設定されているapi keyは何ですか? clientidと同じですか?JavaスクリプトでGoogleログインを統合しましたが、ユーザーメールを見つけることができません

  function logout() 
     { 
      alert('logut'); 
      gapi.auth.signOut(); 
      location.reload(); 
     } 
     function login() 
     { 
      alert('login'); 
      var myParams = { 
       'clientid': 'client id*************', 
       'cookiepolicy': 'single_host_origin', 
       'callback': 'loginCallback', //callback function 
       'approvalprompt': 'force', 
       'scope': 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read' 
      }; 
      gapi.auth.signIn(myParams); 
     } 

     function loginCallback(result) 
     { 
      alert('login call back'); 
      if (result['status']['signed_in']) 
      { 
       alert('if result status signed in'); 
       var request = gapi.client.plus.people.get({ 
          'userId': 'me' 
         }); 
       request.execute(function (resp) 
       { 
        alert('request.execute'); 
        alert(resp.displayName); 
        console.log('ID: ' + resp.id); 
        console.log('Display Name: ' + resp.displayName); 
        console.log('Image URL: ' + resp.image.url); 
        console.log('Profile URL: ' + resp.url); 
       }); 

      } 

     } 
     function onLoadCallback() 
     { 
      gapi.client.setApiKey('api key ***************'); 
      gapi.client.load('plus', 'v1', function() {}); 
     } 

     (function() { 
      alert('default method'); 
      var po = document.createElement('script'); 
      po.type = 'text/javascript'; 
      po.async = true; 
      po.src = 'https://apis.google.com/js/client.js?onload=onLoadCallback'; 
      var s = document.getElementsByTagName('script')[0]; 
      s.parentNode.insertBefore(po, s); 
     })(); 
+0

@Bhagesh Arora –

+0

あなたは最近私の質問を編集しました@Uttam Kumar Roy –

答えて

0

これはあまり見つからないが、それでも私はメールを受け取るためにやっている方法だ。 それはあなたにも役立つかもしれません。

スクリプトのURL

<script src = "https://plus.google.com/js/client:platform.js" async defer></script> 

HTML

<body> 
    <!-- Container with the Sign-In button. --> 
    <div id="gConnect" class="button"> 
     <button class="g-signin" 
      data-scope="email" 
      data-clientid="841077041629.apps.googleusercontent.com" 
      data-callback="onSignInCallback" 
      data-theme="dark" 
      data-cookiepolicy="single_host_origin"> 
     </button> 
     <!-- Textarea for outputting data --> 
     <div id="response" class="hide"> 
     <textarea id="responseContainer" style="width:100%; height:150px"></textarea> 
     </div> 
    </div> 
</body> 

JS

/** 
    * Handler for the signin callback triggered after the user selects an account. 
    */ 
    function onSignInCallback(resp) { 
    gapi.client.load('plus', 'v1', apiClientLoaded); 
    } 

    /** 
    * Sets up an API call after the Google API client loads. 
    */ 
    function apiClientLoaded() { 
    gapi.client.plus.people.get({userId: 'me'}).execute(handleEmailResponse); 
    } 

    /** 
    * Response callback for when the API client receives a response. 
    * 
    * @param resp The API response object with the user email and profile information. 
    */ 
    function handleEmailResponse(resp) { 
    var primaryEmail; 
    for (var i=0; i < resp.emails.length; i++) { 
     if (resp.emails[i].type === 'account') primaryEmail = resp.emails[i].value; 
    } 
    document.getElementById('responseContainer').value = 'Primary email: ' + 
     primaryEmail + '\n\nFull Response:\n' + JSON.stringify(resp); 
    } 

プライマリメールがあなたの希望を取得します Eメール。

関連する問題