没有刷新令牌的Google访问令牌

时间:2019-09-17 21:24:09

标签: php google-api google-oauth

我正在使用the Google Api Client对用户进行身份验证,因此我希望从其YouTube频道中检索实时流的列表。这是我的代码:

require_once 'vendor/autoload.php';
require_once('../../../../wp-load.php');

global $wpdb;

// https://github.com/googleapis/google-api-php-client
$client = new Google_Client();
$client->setAuthConfig('client_secret.json');
$client->setScopes(['https://www.googleapis.com/auth/youtube','https://www.googleapis.com/auth/youtube.readonly']);
$redirect_uri = get_template_directory_uri()."/youtube_streams/";
$client->setAccessType('offline');
$client->setRedirectUri($redirect_uri);

// https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/list

if (isset($_GET['code'])) {
    $token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
    $wpdb->insert('yt_access_token', ['json' => json_encode($token)]);
    echo('<h4>The authentication was successfully saved</h4>');
    die("<pre>".json_encode($token)."</pre>");
}
else {
    $authUrl = $client->createAuthUrl();
    header("Location: ".$authUrl);
    die();
}

问题在于返回的令牌不随refresh_token一起提供,因此不可能获得新的访问令牌。

我是否缺少使刷新令牌返回的内容?

0 个答案:

没有答案