Campaign Manager 360 API Python Script

769 views
Skip to first unread message

Rajan Parmar

unread,
Dec 16, 2020, 11:47:40 PM12/16/20
to Google's DoubleClick Campaign Manager API Forum
Hi Team, 

I want to access the API https://www.googleapis.com/dfareporting/v3.4/userprofiles/profile-id/cities using python. I tried authenticating before hitting this api using https://developers.google.com/doubleclick-advertisers/authorizing#python

But still I am getting following error code even after I got the message "Authorization Successful":


"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [
{
"message": "Login Required.",
"domain": "global",
"reason": "required",
"location": "Authorization",
"locationType": "header"
}
],
"status": "UNAUTHENTICATED"

}

Do I need to anything else?
PFA Python Scirpt

DCMZipcode.py

DCM API (DoubleClick Campaign Mgr)

unread,
Dec 17, 2020, 5:25:35 AM12/17/20
to rajanp...@gmail.com, google-doubleclick-...@googlegroups.com
Hi Rajan,

Thank you for reaching out to us. 

With regard to your concern, it seems that you're not handling the authorization properly which causes an issue.  With this, we would recommend checking out our sample client libraries and implementation which can handle some of the authorization process for you.

Regards,
Google Logo
Teejay Wennie Pimentel
DCM API Team
 


ref:_00D1U1174p._5004Q29SgDJ:ref

Rajan Parmar

unread,
Dec 17, 2020, 8:05:34 AM12/17/20
to Google's DoubleClick Campaign Manager API Forum
I fixed the error. 
I have one query. I created the script and whenever authentication required it opens up auth link in browser and ask to allow certain permission. 
But I want to setup some type of cron which runs on weekly basis to fetch the latest information and deploy it as some service. I cannot manually give permission everytime cron runs right? What is workaround for it ?  


Thanks and Regards 
Rajan Parmar

DCM API (DoubleClick Campaign Mgr)

unread,
Dec 18, 2020, 4:22:01 AM12/18/20
to rajanp...@gmail.com, google-doubleclick-...@googlegroups.com
Hi Rajan,

Thank you for getting back to us, and I'm glad that the issue has been resolved.

As per authorization concern, the browser step is a one time step. Please check the following guide where the example explains to load default credentials: https://developers.google.com/doubleclick-advertisers/authorizing#python

If you want to avoid the browser step, then I recommend using service accounts. Please check the following links:
  1. https://developers.google.com/doubleclick-advertisers/service_accounts
  2. https://github.com/googleads/googleads-dfa-reporting-samples/blob/master/java/v3.4/src/main/java/com/google/api/services/samples/dfareporting/auth/AuthenticateUsingServiceAccount.java

Rajan Parmar

unread,
Jan 13, 2021, 12:55:20 AM1/13/21
to Google's DoubleClick Campaign Manager API Forum
I am not getting an option to associate my user profile to service account (***@googleacount.com) I newly created as mentioned https://developers.google.com/doubleclick-advertisers/service_accounts . Can you please help me with that.

Screenshot 2021-01-12 at 11.29.49 PM.png

DCM API (DoubleClick Campaign Mgr)

unread,
Jan 13, 2021, 5:32:40 AM1/13/21
to rajanp...@gmail.com, google-doubleclick-...@googlegroups.com
Hi there,

As per checking, it appears that you already opened a thread with this concern. Moving forward, kindly refrain from posting to another thread with the same content to for better tracking of the issue. Let's continue our discussion on this thread instead.
Reply all
Reply to author
Forward
0 new messages