首页 > 解决方案 > 无法订阅 onedrive API

问题描述

我尝试通过点击https://graph.microsoft.com/v1.0/subscriptions https://graph.microsoft.com/beta/subscriptions订阅 onedrive webhook

参数是:

"changeType": "created,updated,deleted",
             "notificationUrl": url.
               "resource": "me/drive/root",
               "clientState": "client-specific string",
            "expirationDateTime": "2018-01-01T11:23:00.000Z",

我收到如下错误:

 { error:
   { code: 'InvalidRequest',
     message: 'Server could not process subscription creation payload.',
     innerError:
      { 'request-id': 'id',
        date: '2018-10-16T09:16:46' } } }

我正在本地尝试。

有什么解决办法吗?

标签: onedrive

解决方案


确保您发布了一个 json 请求,这意味着:

  1. 请求正文是一个 json 字符串;
  2. 标题中的“Content-Type”字段,值为“application/json”

如果你使用 Python,有一个捷径:

import requests
url = "https://graph.microsoft.com/beta/subscriptions"
headers = {'Authorization': 'Bearer ' + "YOUR_TOKEN"}
data = {
    "changeType": "created,updated,deleted",
    "notificationUrl": url.
    "resource": "me/drive/root",
    "clientState": "client-specific string",
    "expirationDateTime": "2018-01-01T11:23:00.000Z"
}
resp = requests.post(headers=headers, json=data)

推荐阅读