gpt4 book ai didi

php - Microsoft graph 无法读取 JSON 请求负载

转载 作者:行者123 更新时间:2023-12-02 03:31:34 26 4
gpt4 key购买 nike

我正在尝试在 php 中使用 microsoft graph 创建订阅,但是我目前无法看到出了什么问题。

代码在以下位置被破坏:

protected $http_subscribe = "https://graph.microsoft.com/v1.0/subscriptions";

public function getSubscriptions()
{
if(empty($this->token)) {
dd('no token supplied'); //some debugging
}

$date = $this->endTimeDate->format('Y-m-d'); //This is Carbon date

$time = $this->endTimeDate->format('H:i:s.u');

$response = $this->client->request('POST', $this->http_subscribe, [
'headers' => [
'Authorization' => 'Bearer ' . $this->token,
'Content-Type' => "application/json"
], 'form_params' => [
"changeType" => "created,updated",
"notificationUrl" => "https://website.test/notify",
"resource" => "me/mailFolders('Inbox')/messages",
"expirationDateTime" => $date.'T'.$time,
"clientState" => "secretClientValue"
]
]);

dd($response);
}

我收到的完整错误是:

"""
{\r\n
"error": {\r\n
"code": "BadRequest",\r\n
"message": "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.",\r\n
"innerError": {\r\n
"request-id": "063d9947-80fd-461d-a70e-q0bd8eee9d56",\r\n
"date": "2018-08-07T08:20:54"\r\n
}\r\n
}\r\n
}
"""

现在我明白了错误的意思,我的 json 无效,但是这个数组的 json 格式正确,我使用 Guzzle 作为我的客户端。

最佳答案

您应该使用json选项。试试这个:

$response = $this->client->request('POST', $this->http_subscribe, [
'headers' => [
'Authorization' => 'Bearer ' . $this->token,
],
'json' => [
"changeType" => "created,updated",
"notificationUrl" => "https://website.test/notify",
"resource" => "me/mailFolders('Inbox')/messages",
"expirationDateTime" => $date.'T'.$time,
"clientState" => "secretClientValue",
],
]);

关于php - Microsoft graph 无法读取 JSON 请求负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51722614/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com