2017-04-27 3 views
0

私は自分のウェブサイトでGoogleログインボタンを使用しています。私はユーザーを認証し、ユーザーのプロファイル情報を取得することができます。Google SignInボタンの使用中の追加の許可

私は今、私は彼がグーグルを使用して許可しながら、ユーザーの連絡先を読む必要があり、このIntegrating Google Sign-In into your web app

<div id="my-signin2" ></div> 

gapi.signin2.render('my-signin2', { 
      'scope': 'profile email', 
      'width': 240, 
      'height': 50, 
      'longtitle': true, 
      'theme': 'light', 
      'onsuccess': this.onSuccess, 
      'onfailure': this.onFailure 
     }); 

     onSuccess(googleUser) { 
       var id_token = googleUser.getAuthResponse().id_token; 
       var name = googleUser.getBasicProfile().getName()); 
       var email = googleUser.getBasicProfile().getEmail()); 
       var imageUrl = googleUser.getBasicProfile().getImageUrl()); 

     } 
     onFailure(error) { 
     } 

を追っています。私はすべてのものが正常に動作している範囲

https://www.googleapis.com/auth/contacts.readonly

 gapi.signin2.render('my-signin2', { 
      'scope': 'profile email https://www.googleapis.com/auth/contacts.readonly', 
      'width': 240, 
      'height': 50, 
      'longtitle': true, 
      'theme': 'light', 
      'onsuccess': this.onSuccess, 
      'onfailure': this.onFailure 
     }); 

を追加した連絡先を取得するためのだから、

。 gmailを使用してユーザーが承認した後、ユーザーに許可画面が表示され、許可が求められます。

しかし、ユーザーがアクセス許可を拒否した場合でも、ユーザーはログに記録されません。私は彼が拒否したとしても、私は彼の連絡先を取得しない場合は、そのユーザーにログインしたい。

私は(ユーザーが電子メールを許可した後)についてrequesting additional scopes.

 var options = new gapi.auth2.SigninOptionsBuilder(
       {'scope': 'https://www.googleapis.com/auth/contacts.readonly'}); 

     googleUser = auth2.currentUser.get(); 
     googleUser.grant(options).then(
      function(success){ 
       console.log(JSON.stringify({message: "success", value: success})); 
      }, 
      function(fail){ 
       alert(JSON.stringify({message: "fail", value: fail})); 
      }); 

私がするonSuccessに、この後に使用する場合、それはいつもの方法を失敗することになり読みました。このthread

での議論を1として "popup_closed_by_user"

答えて

0

をエラーを与えることは解決策を見つけました。

追加のスコープを要求するための別のボタンが作成され、ボタンの付与方法が呼び出されました。それはスコープを取得するための

var options = new gapi.auth2.SigninOptionsBuilder(
      {'scope': 'https://www.googleapis.com/auth/contacts.readonly'}); 

が動作していない

は、あなたがメソッドを使用する必要があり、このようなオプションを設定した場合

let googleUser = auth2.currentUser.get(); 

var options = new gapi.auth2.SigninOptionsBuilder(); 
options.setScope('https://www.googleapis.com/auth/contacts.readonly'); 


googleUser.grant(options).then(
     function(success){ 
      console.log(JSON.stringify({message: "success", value: success})); 
     }, 
     function(fail){ 
      alert(JSON.stringify({message: "fail", value: fail})); 
}); 
関連する問題