I'm trying to request information from an API. The way I'm passing in the OAUTH Token is wrong, I assume.
import requests
import json
URL = "https://api.direct.yandex.com/json/v5/keywords"
token = "/* Access Token */"
PARAMS = {
'Authorization': "Bearer " + token,
'Accept-Language': "en",
'processingMode': "auto",
}
BODY = {
'method': "CreateNewWordstatReport",
'param': {
"Phrases": ['pipeline'],
"GeoID": [1,-219]
}
}
#jdata = json.dumps(PARAMS, ensure_ascii=False).encode ('utf8')
body = json.dumps(BODY, indent=4)
response = requests.post(URL, body, headers=PARAMS)
response.encoding = 'utf-8'
#response = requests.get(url = URL, params = PARAMS)
print(response.status_code)
print(response.url)
print(response.json())
The Commented Lines are potential alternatives to the three lines in-between. How do I use .post() and .get() correctly here, in order to pass in the token? The current response is shown:
202
https://api.direct.yandex.com/json/v5/keywords
{'error': {'request_id': '1891/* some more numbers */0199', 'error_code': 8000, 'error_detail': 'Not able to process JSON/XML', 'error_string': 'Invalid request'}}
Thanks much for any help!