MicrosoftDocs / Advertising-docs

Creative Commons Attribution 4.0 International
15 stars 59 forks source link

Error when using python example #782

Closed rokkerruslan closed 4 years ago

rokkerruslan commented 4 years ago

Using https://docs.microsoft.com/en-us/advertising/guides/walkthrough-desktop-application-python?view=bingads-13

Environment:

Follow the documentation create a file and edit two constants CLIENT_ID and DEVELOPER_TOKEN.

Run:

$ python3 get-started.py

After run a get:

You need to provide consent for the application to access your Microsoft Advertising accounts. After you have granted consent in the web browser for the application to access your Microsoft Advertising accounts, please enter the response URI that includes the authorization 'code' parameter:

Ok, authenticate on web site success and I get the link.

After copy link to terminal a get again:

You need to provide consent for the application to access your Microsoft Advertising accounts. After you have granted consent in the web browser for the application to access your Microsoft Advertising accounts, please enter the response URI that includes the authorization 'code' parameter:

Ok, authenticate on web site success and I get the second link.

After copy link to terminal a get:


  File "/Users/rokker/w/ads/.venv/lib/python3.7/site-packages/bingads/authorization.py", line 674, in get_access_token
    r.raise_for_status()
  File "/Users/rokker/w/ads/.venv/lib/python3.7/site-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://login.microsoftonline.com/common/oauth2/v2.0/token

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bing.py", line 73, in authenticate_with_oauth
    request_user_consent(authorization_data)
  File "bing.py", line 92, in request_user_consent
    authorization_data.authentication.request_oauth_tokens_by_response_uri(response_uri=response_uri)
  File "/Users/rokker/w/ads/.venv/lib/python3.7/site-packages/bingads/authorization.py", line 443, in request_oauth_tokens_by_response_uri
    requireliveconnect=self._require_live_connect
  File "/Users/rokker/w/ads/.venv/lib/python3.7/site-packages/bingads/authorization.py", line 677, in get_access_token
    raise OAuthTokenRequestException(error_json.get('error'), error_json.get('error_description'))
bingads.exceptions.OAuthTokenRequestException: error_code: invalid_client, error_description: AADSTS70002: The provided request must include a 'client_secret' input parameter.
Trace ID: 86cb461e-7047-4ac3-816c-d51f60081900
Correlation ID: 5619523c-dff4-4b7e-bc34-83fdf8cd4230
Timestamp: 2020-03-11 08:03:24Z

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/rokker/w/ads/.venv/lib/python3.7/site-packages/bingads/authorization.py", line 674, in get_access_token
    r.raise_for_status()
  File "/Users/rokker/w/ads/.venv/lib/python3.7/site-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://login.microsoftonline.com/common/oauth2/v2.0/token

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bing.py", line 387, in <module>
    authenticate(authorization_data)
  File "bing.py", line 35, in authenticate
    authenticate_with_oauth(authorization_data)
  File "bing.py", line 77, in authenticate_with_oauth
    request_user_consent(authorization_data)
  File "bing.py", line 92, in request_user_consent
    authorization_data.authentication.request_oauth_tokens_by_response_uri(response_uri=response_uri)
  File "/Users/rokker/w/ads/.venv/lib/python3.7/site-packages/bingads/authorization.py", line 443, in request_oauth_tokens_by_response_uri
    requireliveconnect=self._require_live_connect
  File "/Users/rokker/w/ads/.venv/lib/python3.7/site-packages/bingads/authorization.py", line 677, in get_access_token
    raise OAuthTokenRequestException(error_json.get('error'), error_json.get('error_description'))
bingads.exceptions.OAuthTokenRequestException: error_code: invalid_client, error_description: AADSTS70002: The provided request must include a 'client_secret' input parameter.
Trace ID: 05b61f13-adf4-419d-bed2-999d72db1a00
Correlation ID: 16dedbdf-171e-453d-bbb4-d01614f6582e
Timestamp: 2020-03-11 08:03:37Z```
eric-urban commented 4 years ago

@rokkerruslan the sample does work for me with a native console app. Did you register a web app with client secret? In that case please try updating the sample to use OAuthWebAuthCodeGrant (and include the client secret) instead of OAuthDesktopMobileAuthCodeGrant. Otherwise please consider posting the repro steps (without credentials) via the developer forum or contact support for additional assistance.