dpir3950 2018-08-07 08:50
浏览 92
已采纳

Microsoft图无法读取JSON请求有效负载

I'm trying to create subscriptions with microsoft graph in php, however I am unable to see what is going wrong at this point.

The code is breaking at the following:

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);
}

The full error I'm getting is:

"""
{

  "error": {

    "code": "BadRequest",

    "message": "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.",

    "innerError": {

      "request-id": "063d9947-80fd-461d-a70e-q0bd8eee9d56",

      "date": "2018-08-07T08:20:54"

   }

  }

}
"""

Now I get what the error says, my json would be invalid, however this array is in correct json format, I'm using Guzzle as my Client.

  • 写回答

1条回答 默认 最新

  • doudeng8691 2018-08-07 14:46
    关注

    You should use json option. Try this:

    $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",
       ],
    ]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向