I tried to get access token and refresh token using OAuth2WebServerFlow in python. but it's throwing error oauth2client.client.FlowExchangeError: invalid_grantMalformed auth code.
Example Code
from oauth2client.client import OAuth2WebServerFlow
def retrieve_data():
"""
Run through the OAuth flow and retrieve credentials.
Returns a dataset (Users.dataSources.datasets):
https://developers.google.com/fit/rest/v1/reference/users/dataSources/datasets
"""
CLIENT_ID = 'XXXXX'
CLIENT_SECRET = 'XXXX'
OAUTH_SCOPE = ['https://www.googleapis.com/auth/userinfo.email']
REDIRECT_URI = 'XXXXXXX'
flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE, REDIRECT_URI)
authorize_url = flow.step1_get_authorize_url()
print('Go to the following link in your browser:')
print(authorize_url)
code = input('Enter verification code: ')
print(code)
google_data = flow.step2_exchange(code)
# # http = httplib2.Http()
# # http = google_data.authorize(http)
# print(google_data)
# access_token = google_data.token_response['access_token']
# print(access_token)
retrieve_data()
I have auth code also. i tried to pass code in step2_exchange method.it's throwing this error ('oauth2client.client.FlowExchangeError: invalid_grantMalformed auth code.') how to solve this issuue.