Office 365 API - Request returned HTTP error 400

坚强是说给别人听的谎言 提交于 2020-01-06 19:58:50

问题


I'm trying to follow a tutorial where I pull mail and calendar events from the Office 365 API. I was able to pull mail but when I try to pull calendar events I get back error 400 which, from some Googling, is apparently that one of my headers being too long. I put a var_dump(getallheaders()); and can see the following:

array (size=10)
  'Host' => string 'localhost:9999' (length=14)
  'Connection' => string 'keep-alive' (length=10)
  'Pragma' => string 'no-cache' (length=8)
  'Cache-Control' => string 'no-cache' (length=8)
  'Accept' => string 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' (length=74)
  'Upgrade-Insecure-Requests' => string '1' (length=1)
  'User-Agent' => string 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36' (length=121)
  'Accept-Encoding' => string 'gzip, deflate, sdch' (length=19)
  'Accept-Language' => string 'en-US,en;q=0.8' (length=14)
  'Cookie' => string 'PHPSESSID=286082ac61749c4e351c1218495859bb; SQLiteManager_currentLangue=2' (length=73)

This all looks fine to me. What am I missing?

EDIT - when I do $response = curl_exec($curl); followed by var_dump($response); I get this:

string '{"error":{"code":"RequestBroker-ParseUri","message":"The $orderby expression must evaluate to a single value of primitive type."}}' (length=130)

The function with $orderby expression is this:

    public static function getEvents($access_token, $user_email) {

        $getEventsParameters = array (
            // Only return Subject, Start, and End fields
            "\$select" => "Subject,Start,End",
            // Sort by Start, oldest first
            "\$orderby" => "Start",
            // Return at most 10 results
            "\$top" => "10"
        );

        $getEventsUrl = self::$outlookApiUrl."/Me/Events?".http_build_query($getEventsParameters);


        return self::makeApiCall($access_token, $user_email, "GET", $getEventsUrl);
    }

回答1:


Ok. The issue is that we changed the type for the Start property. It's now a complex type. You want to sort on the DateTime property of the Start property, so you'd want to change this line:

"\$orderby" => "Start",

To this:

"\$orderby" => "Start\DateTime",

I thought we had updated the tutorials, but I see that the PHP one isn't updated. I'll work on getting that fixed today!



来源:https://stackoverflow.com/questions/34687028/office-365-api-request-returned-http-error-400

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!