ERROR: invalid_grantMalformed auth code when getting refresh token (Python SDK)

928 views
Skip to first unread message

SIBI S

unread,
Mar 27, 2018, 11:36:54 AM3/27/18
to Google's DoubleClick for Publishers API Forum
Hi,

I am setting up API access for dfp based on the instructions given here 


I am using a script as below

from googleads import oauth2
from oauth2client import client

flow = client.OAuth2WebServerFlow(
    client_id = CLIENT_ID,
    client_secret = CLIENT_SECRET,
    scope = oauth2.GetAPIScope('dfp'),
    user_agent = 'Test',
    redirect_uri = REDIRECT_URI
)

auth_uri = flow.step1_get_authorize_url()

I get an auth_uri as below


I use this url to get an auth_code

Now when I run 

credentials = flow.step2_exchange(auth_code)

I get the following error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/oauth2client/client.py", line 2089, in step2_exchange
    raise FlowExchangeError(error_msg)
oauth2client.client.FlowExchangeError: invalid_grantMalformed auth code


Any idea what could be going on here ?

Thanks

Sibi


Nicholas Figeac (DFP API Team)

unread,
Mar 27, 2018, 2:05:30 PM3/27/18
to Google's DoubleClick for Publishers API Forum
Hello Sibi,

It looks like the auth code you are using is getting malformed. You can actually follow this Python example in our client library for generating the credentials. Give that a try and let me know if it works. If you continue to have issues, could you also provide me the redirect uri you are using? Please don't share client id/secret or tokens. You can also respond back using "Reply privately to author".

Thanks,
Nicholas Figeac, DFP API Team

arvind...@berkeley.edu

unread,
Oct 27, 2018, 10:34:35 PM10/27/18
to Google Ad Manager API Forum
Hello,

I'm having the exact same issue. It seems that the link that you posted does not seem to be working anymore. Do you know if there is somewhere else I can look to hopefully resolve this issue with OAuth2 authentication? Thanks!

Sincerely yours,
Arvind
Reply all
Reply to author
Forward
0 new messages