0
votes

I am using Google Photos API. As mentioned in API i stored refresh token for the next use after token expires. After 1 hour i am requesting to refresh client it produces error

"error": "invalid_grant", "error_description": "Token has been expired or revoked."

Here is my code:

  $_SESSION['credentials'] = new UserRefreshCredentials(
        $scopes,
        [
            'client_id' => $clientId,
            'client_secret' => $clientSecret,
            'refresh_token' => $refreshToken
        ]
    );

    $photosLibraryClient = new PhotosLibraryClient(['credentials' => $_SESSION['credentials']]);
1
as mentioned in documentation The UserRefreshCredentials will use the refresh token to 'refresh' the credentials whenthey expire. i am storing refresh token in session . after 1 hour i am not able to refresh my client using Refresh tokenFarhan Siddique
You are correct. I misread or misunderstood the code above. Do you get the error on UserRefreshCredentials or PhotosLibraryClient?Jenea Vranceanu
i am getting errro on using PhotosLibraryClientFarhan Siddique

1 Answers

0
votes
const { google } = require('googleapis');

function refreshToken() {
    const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris);
    oAuth2Client.refreshAccessToken((err, tokens) => {
        oAuth2Client.setCredentials(tokens);
        console.log('YAYYYYYY! Token is refreshed!!!');
        const data = {
            credentials: {
                access_token: tokens.access_token
            }
        };
        console.log(data);
    })
}