2013-11-26 21 views
0

我的工作outlook api,我收到以下错误代码响应前景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>"; 

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

回答

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(); 
      } 
     } 
    } 
相关问题