-
I´ve been looking for it in the docs and elsewhere, but I can´t seem to figure out how to get a CHROME_REFRESH_TOKEN for the .env file for submitting to the app store. Things I figured out (I think): Things I have tried: Then created a OAuth flow (web), which I know gives a refresh token (with the scope https://www.googleapis.com/auth/chromewebstore), which works, but the resulting call fails with "Token has been expired or revoked." My flow (python): from __future__ import print_function
import os.path
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/chromewebstore']
client_secrets_file = 'google_client_secret.json'
token_file = 'google_token.json'
def main():
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists(token_file):
creds = Credentials.from_authorized_user_file(token_file, SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
client_secrets_file, SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open(token_file, 'w') as token:
token.write(creds.to_json())
if __name__ == '__main__':
main() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Figured it out: Forgot to add the api to the project in the google console. So, the code should work for you :) |
Beta Was this translation helpful? Give feedback.
Figured it out: Forgot to add the api to the project in the google console.
So, the code should work for you :)