2016-03-01 82 views
1

我用在“https://github.com/jasonjoh/php-tutorial”中描述的基本的例子/教程,并试图添加“$搜索”参数中的getMessages()函数搜索参数不与Outlook工作RESTAPI

$getMessagesParameters = array (
     // Message Search Conditions 
     "\$search" => 'subject:"pizza"', 
     // Only return Subject, ReceivedDateTime, and From fields 
     "\$select" => "Subject,Body", 
     // Return at most 10 results 
     "\$top" => "10" 
    ); 
    $getMessagesUrl = self::$outlookApiUrl."/Me/Messages?".http_build_query($getMessagesParameters); 
    $response = $this->makeApiCall($access_token, $user_email, "GET", $getMessagesUrl); 

的请求返回错误400

不知道可能是正确的语法

我已经提到了以下链接

https://msdn.microsoft.com/office/office365/api/complex-types-for-mail-contacts-calendar#UseODataqueryparametersSearchrequests

https://msdn.microsoft.com/en-us/library/cc513841%28v=office.12%29.aspx

https://support.office.com/en-us/article/Learn-to-narrow-your-search-criteria-for-better-searches-in-Outlook-d824d1e9-a255-4c8a-8553-276fb895a8da

如果有人有更好的想法通过邮件进行搜索,请建议...

+0

哪些是您使用API​​的版本?是否有可能显示最终请求url(您可以通过fiddler或您的浏览器调试器 - 网络部分获取)? –

+0

@BenoitPatra我们不能使用浏览器调试器来捕获url ...请求是从服务器发出的......无论如何你可以得到这个想法......代码使用'http_build_query()'和'$ outlookApiUrl = “https://outlook.office.com/api/v2.0”'。结果网址看起来类似于'https://outlook.office.com/api/v2.0/Me/Messages?$search=subject:"pizza"&$select=Subject,Body&$orderby=ReceivedDateTime DESC&$顶部= 10'和特殊字符可能是网址编码...重点是当我删除'$搜索'参数,没有错误返回 –

回答

0

我已经想通了确切的问题...

问题是不是与搜索参数规格/服务器REST端点...

但问题是,我们如何将查询参数发送到服务器...

我们不应该URL编码数据。

,但我们需要的结果网址

这与+更换空间是解决方案,我想出来的......

$search_AQS = '"Subject:(pizza+OR+hamburger+OR+tacos)+AND+subject:(NOT+beef+NOT+pork)"'; 
    $getMessagesParameters = array (
     "\$search" => $search_AQS, 
     "\$select" => "Subject,Body", 
     "\$top" => "10" 
    ); 
    $tmp_uripiece = http_build_query($getMessagesParameters); 
    $tmp_uripiece = urldecode($tmp_uripiece); 
    $getMessagesUrl = self::$outlookApiUrl.'/Me/Messages?'.$tmp_uripiece; 
    $response = $this->makeApiCall($access_token, $user_email, "GET", $getMessagesUrl); 

耶!微软还支持搜索功能,在它们的端点...但他们应该有更多的例子已经证明......

每个人都感谢您的支持...

0

在搜索结果中不能使用排序依据。 请参阅https://msdn.microsoft.com/en-us/office/office365/api/complex-types-for-mail-contacts-calendar#UseODataqueryparametersSearchrequests $ search = subject:“pizza”应该是$ search = subject:pizza。但那也行不通。 我用$搜索=比萨饼和工作(不排序依据)

+0

虽然这可能在理论上回答这个问题,[这将是更可取的](/ /元.stackoverflow.com/q/8259)在这里包含答案的基本部分,并提供供参考的链接。 – manetsus

+0

@max,对不起,我已经从参数中删除了'$ orderby' ......但问题就像你说的,当我在搜索查询中包含运算符':'时,'$ search = subject :pizza'我得到一个http 400错误...是来自curl()还是来自Outlook REST API服务器端点结果?我不确定... –