api-samples icon indicating copy to clipboard operation
api-samples copied to clipboard

How to permanently authorize my application? Do I always need to use a new authorization code?

Open ricardoreis opened this issue 4 years ago • 3 comments

I want to make a bot that comments and likes videos. I can do it but I always need to visit a URL to authorize the application for each video. How to permanently authorize?

image

ricardoreis avatar Apr 16 '20 04:04 ricardoreis

Use the following code to get a refresh_token upon the initial request.

        $client = new Google_Client([
            'access_type' => 'offline'
        ]);

You will only get a refresh token once so if your app already has access to your Google account you will need to revoke it at your security settings on https://myaccount.google.com/.

Casmo avatar Apr 23 '20 21:04 Casmo

@ricardoreis Don't forget to add promt: 'consent' to the client to get the refresh token

rahul0tripathi avatar May 21 '20 18:05 rahul0tripathi

You can actually initiate your own instance of the Credentials class, then pass as parameters the token, refresh_token, client_id, and client_secret.

from google.oauth2.credentials import Credentials

SmithOrlando avatar Dec 21 '22 10:12 SmithOrlando