我正在尝试从 API 请求信息。我认为我传递 OAUTH 令牌的方式是错误的。
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())
注释行是中间三行的潜在替代品。如何在此处正确使用 .post() 和 .get() 以传递令牌?显示当前响应:
202
https://api.direct.yandex.com/json/v5/keywords
{'error': {'request_id': '1891/* 更多数字 */0199', 'error_code': 8000, 'error_detail': '无法处理 JSON/XML', 'error_string': '无效请求' }}
非常感谢您的帮助!