0

I'm using the Google Api Client to authenticate my user so I'm aple to retrieve a list of live streams from his youtube channel. This is my code:

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();
}

The problem is that the token returned does not come with the refresh_token, so it's not possible to get a new access token.

Is there something I'm missing that would make the refresh token return?

André Luiz
  • 6,642
  • 9
  • 55
  • 105

0 Answers0