'How to create Flow object -credentials on Heroku

so I tried a few suggestions that were mentioned in this link -https://stackoverflow.com/questions/47446480/how-to-use-google-api-credentials-json-on-heroku. first, I set a config variable on Heroku(GOOGLE_APPLICATION_CREDENTIALS,GOOGLE_CREDENTIALS) and it did load the credentials. but I am still get an error in creating the Flow object, I tried what @Chrisjan suggest in the link and add this line to .procfile -

echo ${GOOGLE_CREDENTIALS} > /app/credentials.json

but I am still getting errors in creating the flow object.

my code:

json_str = os.environ.get('GOOGLE_CREDENTIALS')
client_secrets_dict = json.loads(json_str)

def create_flow():
flow = Flow.from_client_secrets_file(
    client_secrets_file=client_secrets_filename,
    scopes=['openid', 'https://www.googleapis.com/auth/userinfo.profile',
            'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/gmail.readonly'],
    redirect_uri=client_secrets_dict['web']['redirect_uris'][1]
)
return flow

the problem is in the create_flow function, in the line client_secrets_file=client_secrets_filename.

client_secrets_filename is equal to : tried -1. "credentials.json" 2. "/app/credentials.json"

I also tried to use the buildpack but it didn't work for me. My first purpose was to use the credentials.json in those lines without the need to upload the file to GitHub.

would like to get help! thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source