BingAds Client State, oauth_web_auth_code_grant
Asked Answered
R

1

5

I would like to get my custom "Reports" data from my BingAds out with the bingads API. I am using the KeywordsAds.py example, which may not be the correct one. However, my problem starts with the authentication, I cannot seem to find all the authentication inputs needed. I am missing examples in like, so I know if I am inserting the right data:

authorization_data=AuthorizationData(
    account_id='123456789', --instead of just None
    customer_id='123456789', --instead of just None
    developer_token='12345A1234567891', --instead of just DeveloperTokenGoesHere
    authentication='OAuthWebAuthCodeGrant', --instead of just None

)

1) To the code above, what authentication do I need to choose for the WebAPI? (2) And for my problem stated, do I need to use a WebAPI, or would a Web platform be more useful?

CLIENT_ID='ClientIdGoesHere'
CLIENT_STATE='ClientStateGoesHere'

3) What is the Client_State? I did google this term, but did not find an explanation. What values could/need to be inserted?

And lastly, I do not find the client_secret and redirection_uri in the example code, but it is stated on the Getting Started page for Python on Bing:

oauth_web_auth_code_grant = OAuthWebAuthCodeGrant(
    client_id=CLIENT_ID,
    client_secret=CLIENT_SECRET,
    redirection_uri=REDIRECTION_URI

Is this necessary to fill in?

Repressive answered 20/6, 2017 at 5:57 Comment(0)
R
7

So, I have solved the problem some time back.

The first code block is correct, this is how the examples would look like, just replace the numbers in account_id and customer_id. The developer_token has numbers and letters as displayed in my question. For the authentication, use 'OAuthWebAuthCodeGrant'.

To answer question 1: The WebAPI works, (2) and for CLIENT_ID use the WebAPI's Application ID URI, the part after api://.

Q3: The CLIENT_STATE I left as is, it is not needed.

The last code block int he question is not needed.

If you are a beginner like me and need some help, I made a quick and dirty Python template. It downloads my report to CSV, then I import it to Pandas where I clean the dataset, then I write it again out to CSV, and finally upload it to Google Analytics here

Repressive answered 4/9, 2017 at 12:12 Comment(3)
Hey @ccasimiro9444, i know its been a long time since this issue, but i having trouble in running your script. After minimal modifications, I am able to get account details but reports are coming as None. Please suggestFingernail
Hi @Shivanshu, its been too long to remember. but maybe have a look here github.com/ccasimiro9444/my_templates/blob/master/…Repressive
Hey @ccasimiro9444, seems bingapi is a bit buggy, though after few hit and trials, i got my script working. :)Fingernail

© 2022 - 2024 — McMap. All rights reserved.