I am trying to create a google credentials object to access google drive. I have the tokens and user data stored in a session thus I am trying to create the object without loading them from a credentials.json file. I am handling the authentication when a user first logs in the web app and storing the tokens inside the user session, the session has a time out of 24 hours same as the default access token thus after 24 hours the user is requested to log in again so a new session with a valid access token is created. So my idea is to reuse the access token to limit the amount of log ins and improve user experience.
This is a small piece of code on how I'm trying to create the google credentials object
from oauth2client.client import GoogleCredentials
access_token = request.session['access_token']
gCreds = GoogleCredentials(
access_token,
os.getenv('GOOGLE_CLIENT_ID'),
os.getenv('GOOGLE_CLIENT_SECRET'),
refresh_token=None,
token_expiry=None,
token_uri=GOOGLE_TOKEN_URI,
user_agent='Python client library',
revoke_uri=None)
build('drive', 'v3', credentials = gCred)
Whenever I try to run this code I get the following error:
Insufficient Permission: Request had insufficient authentication scopes.". Details: "[{'domain': 'global', 'reason': 'insufficientPermissions', 'message': 'Insufficient Permission: Request had insufficient authentication scopes.'}]"
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}