为Microsoft Graph API创建订阅:订阅验证请求失败

2024-06-25 06:59:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试为Microsoft Graph API创建订阅。然而,我得到了错误

Subscription validation request failed. Response must exactly match validationToken query parameter.

验证请求如下所示:

POST /?validationToken=Validation%3a+Testing+client+application+reachability+for+subscription+Request-Id%3a+c69b04df-f3d3-411c-8ceb-7f1ad8b7a927 HTTP/1.1

使用FastApi,发送验证请求的API如下所示

from fastapi import FastAPI

app = FastAPI()

@app.post("/")
def read_call_record(validationToken):
    data = {"validationToken": validationToken}
    return data

返回的数据变量如下所示:

{'validationToken': 'Validation: Testing client application reachability for subscription Request-Id: c69b04df-f3d3-411c-8ceb-7f1ad8b7a927'}

有人能帮忙吗


Tags: clientapiappfordataapplicationrequesttesting
2条回答

您的代码需要对validationToken查询参数进行Url解码,并将其返回到图形

documentation开始,您的响应必须在10秒内发生,并具有以下属性:

  • A status code of HTTP 200 OK.
  • A content type of text/plain.
  • A body that includes the URL decoded validation token. Simply reflect back the same string that was sent in the validationToken query parameter.

Important: If the client returns an encoded validation token, the validation will fail.

我自己找到了雨篷。以下是有效的功能:

@app.post("/")
def read_call_record(validationToken):
    return Response(content=validationToken, media_type='text/plain')

相关问题 更多 >