outlook api给出错误代码请求参数丢失

时间:2013-11-26 19:47:45

标签: api outlook

我正在处理outlook api,我在响应中收到以下错误代码

"error": {
      "code": "request_parameter_missing", 
      "message": "The request entity body is missing a required parameter. The request must include at least one of these parameters: 'first_name', 'last_name', 'emails', 'employer'."
   }

这是我的代码

header('Content-Type: application/json; charset=utf-8');

$access_token = TOKEN;
$api_url = "https://apis.live.net/v5.0/me/contacts?&access_token=".$access_token;

$curl = curl_init($api_url);
$curl_data = array(
    'first_name' => "Roberto",
    'last_name' => "Tamburello"
);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$curl_response = curl_exec($curl);
echo"<pre>";
print_r($curl_response);

echo "</pre>";

我一直在寻找几个小时,我似乎无法理解我做错了什么。任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

我也在努力解决这个问题。对我来说,内容类型标题未正确设置为“application / json”,因此即使数据存在,它也无法识别它。修复这个为我删除了错误。 不确定问题究竟在哪里,但认为这可能对其他人有所帮助。这是我在.net

中的请求
    var requestUrl = " https://apis.live.net/v5.0/me/contacts";

    //set body data
    var data = JsonConvert.SerializeObject(liveContact); 
    //liveContact is a custom object for storing contact data
    byte[] byteArray = Encoding.UTF8.GetBytes(data);

    WebRequest req = HttpWebRequest.Create(requestUrl);
    req.Headers.Add("Authorization", "Bearer " + "...access token...");
    req.Method = "POST";
    req.ContentType = "application/json";
    req.ContentLength = byteArray.Length;

    using (Stream dataStream = req.GetRequestStream()) {
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();
    }

    using (WebResponse response = await req.GetResponseAsync()) {
        using (var dataStream = response.GetResponseStream()) {
            using (StreamReader reader = new StreamReader(dataStream)) {
                string responseFromServer = reader.ReadToEnd();
            }
        }
    }