2016-07-08 15 views
3

私はrefresh_tokenに問題があります。私はまったくそれを得ていない。ログイン後最初にこのトークンを取得した後、そのrefresh_tokenが返されないことを確認しました。 「google api - no refresh_token

connectGp: function() { 

var self = this; 

this.auth2.grantOfflineAccess({'redirect_uri': 'postmessage'}).then(

function(response) { 
    $('.gp-button').addClass('loading'); 
    var vars = { 
     code: response.code 
    }; 
    $.ajax({ 
     url: myUrl+"/connect-google", 
     data: vars, 
     type: "GET", 
     success: function(response) { 
      window.location.reload(); 
     } 
    }); 
}); 
}, 

その後、PHP Iに:ユーザーがボタンをクリックして "YouTubeに接続し、" 応答コードは '/接続-Googleのルートに送信されたときに

initGp: function() { 

      requirejs(['google'], 
      function (gapi) { 

       gapi.load('auth2', function() { 
       this.auth2 = gapi.auth2.init({ 
         client_id: 'client_id', 
         scope: 'https://www.googleapis.com/auth/youtube.readonly https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email' 
        }); 
       }.bind(this)); 
      }.bind(this));    
     }, 

次:第一の方法は、GAPIを初期化していますve got:

$googleClient = new \Google_Client(); 
$googleClient->setClientId($client_id); 
$googleClient->setClientSecret($client_secret); 
$googleClient->setRedirectUri('postmessage'); 
$googleClient->setAccessType("offline"); 
$googleClient->setScopes($scopes); 


$token = $googleClient->authenticate($code); 
$access_token = $googleClient->getAccessToken(); 
var_dump($access_token); 

ただし、アクセストークンで私はrefresh_tokenを受け取っていません。どうして ?それはbeacuseです私は 'postmessage'を使用していますか?

答えて

1

毎回refresh_tokenを試してみることができます。

$googleClient->setApprovalPrompt('force'); 

その後、アプリケーションの構築が完了したら、この行を削除できます。それが役に立てば幸い。

+0

これは現在、新しいライブラリに置き換えられた機能を知っていますか? – cevizmx

関連する問題