office365 php中的批处理请求发出错误请求

office365 php中的批处理请求发出错误请求,php,office365,microsoft-graph-api,office365api,Php,Office365,Microsoft Graph Api,Office365api,我正在使用Office365在PHP中同步电子邮件。Office 365 REST API支持批处理请求。我曾尝试使用Office 365 REST API来检索电子邮件,但到目前为止,我收到了一个“BadRequest”回复。任何帮助都将不胜感激。下面是示例代码 $url = 'https://graph.microsoft.com/v1.0/$batch'; $headers = array( "Authorization: Bearer ".$accessToken, "

我正在使用Office365在PHP中同步电子邮件。Office 365 REST API支持批处理请求。我曾尝试使用Office 365 REST API来检索电子邮件,但到目前为止,我收到了一个“BadRequest”回复。任何帮助都将不胜感激。下面是示例代码

$url = 'https://graph.microsoft.com/v1.0/$batch';

$headers = array(
    "Authorization: Bearer ".$accessToken,
    "Content-Type: application/json"
);

$msgid1 = "AQMkADAwATNiZmYAZC1kMjFjLWUyMTUtMDACLTAPwAAAHzY91EAAAA=";
$msgid2 = "AQMkADAwATNiZmYAZC1kMjFjLWUyMTUtDACLTvpPwAAAHzY91AAAAA=";
$msgid3 = "AQMkADAwATNiZmYAZC1kMjFjLWUyMTRRRBGUtMDACLAAHzY908AAAA=";

$params = array(
    'requests' => array(
        array( 
            "id" => "1",
            "method" => "GET",
            "url" => "/me/messages/$msgid1/attachments"
        ),
        array(
            "id" => "2",
            "method" => "GET",
            "url" => "/me/messages/$msgid2/attachments"
        ),
        array(
            "id" => "3",
            "method" => "GET",
            "url" => "/me/messages/$msgid3/attachments"
        )
    )
);

$curl = curl_init($url);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($curl);

作为响应,我收到无效的批处理有效负载格式消息。

Oh。。我的代码有错误

curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode($params))

代替 curl_setopt($curl,CURLOPT_POSTFIELDS,$data)