google drive api调用中的Entity.resource错误

时间:2017-03-10 07:05:44

标签: python django google-drive-api webhooks

连接到Google云端硬盘后,我想关注用户更改。

credentials = json.loads(flow.step2_exchange(code).to_json())

headers = {'Authorization': 'Bearer {}'.format(credentials['access_token']), 'Content-Type': "application/json"}
token_url = 'https://www.googleapis.com/drive/v3/changes/startPageToken'

token_resp = requests.get(token_url, headers=headers)
pageToken = json.loads(token_resp.content)['startPageToken']

url = 'https://www.googleapis.com/drive/v3/changes/watch?pageToken={}&alt=json'.format(pageToken)
headers = {'Authorization': 'Bearer {}'.format(credentials['access_token']),}
data = {
    "id": str_tools.random_str(40),
    "type": "web_hook",
    "address": my_url
}

response = requests.post(url, data=json.dumps(data), headers=headers)

我收到此错误

{
    "error": {
        "errors": [
            {
                "domain": "global",
                "reason": "required",
                "message": "entity.resource"
            }
        ],
        "code": 400,
        "message": "entity.resource"
    }
}

这意味着什么“entity.resource”以及如何解决此错误

感谢。

1 个答案:

答案 0 :(得分:0)

我忘了在请求标头中添加'Content-Type': 'application/json'