Skip to content

Instantly share code, notes, and snippets.

@X-Gorn
Created August 6, 2023 04:27
Show Gist options
  • Save X-Gorn/6fde8b6bc72122e87e887121c420921f to your computer and use it in GitHub Desktop.
Save X-Gorn/6fde8b6bc72122e87e887121c420921f to your computer and use it in GitHub Desktop.
Generate Google Drive Token
import requests
client_id = '123456-abcdefgh.apps.googleusercontent.com'
client_secret = 'abcdefgh'
auth_link = 'https://accounts.google.com/o/oauth2/auth?client_id={client_id}&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&approval_prompt=auto'.format(client_id=client_id)
code = input('Get and paste your auth code from: {auth_link}\n\n'.format(auth_link=auth_link))
x = requests.post(
url="https://www.googleapis.com/oauth2/v4/token",
data={
'code': code,
'client_id': client_id,
'client_secret': client_secret,
'redirect_uri': "urn:ietf:wg:oauth:2.0:oob",
'grant_type': "authorization_code"
}
)
data = x.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment