Php 谷歌api-无刷新令牌

Php 谷歌api-无刷新令牌,php,google-api-client,Php,Google Api Client,我的刷新令牌有问题。我一点也不明白。我读到我只有在登录后第一次得到这个令牌,在这个刷新之后,令牌将不会被返回。第一种方法是初始化gapi: initGp: function() { requirejs(['google'], function (gapi) { gapi.load('auth2', function() { this.auth2 = gapi.auth2.init

我的刷新令牌有问题。我一点也不明白。我读到我只有在登录后第一次得到这个令牌,在这个刷新之后,令牌将不会被返回。第一种方法是初始化gapi:

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));             
        },
接下来,当用户单击“连接到YouTube”按钮时,响应代码将发送到“/Connect google”路径:

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中,我得到:

$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);

但在访问令牌中,我没有收到刷新令牌。为什么?是因为我在使用“postmessage”吗?

您可以试试这个,每次都可以获得刷新令牌

$googleClient->setApprovalPrompt('force');

然后,一旦完成应用程序的构建,就可以删除这一行。希望能有帮助

你知道现在哪个函数用新库取代了这个吗?