我将使用电子邮件审核API 为用户abc列出我的用户电子邮件。到目前为止我的代码是
$xml = "
<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>
<apps:property name='destUserName' value='abc'/>
<apps:property name='beginDate' value='2009-06-15 00:00'/>
<apps:property name='endDate' value='2015-06-30 23:20'/>
<apps:property name='incomingEmailMonitorLevel' value='FULL_MESSAGE'/>
<apps:property name='outgoingEmailMonitorLevel' value='HEADER_ONLY'/>
<apps:property name='draftMonitorLevel' value='FULL_MESSAGE'/>
<apps:property name='chatMonitorLevel' value='FULL_MESSAGE'/>
</atom:entry>
";
$abc = 'mypublicAPI';
$cred = new Google_Auth_AssertionCredentials(
'myEmail',
array(
'https://apps-apis.google.com/a/feeds/compliance/audit',
),$abc
);
$client->setAssertionCredentials($cred);
$domain = 'mydomain';
$username = 'abc';
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$url = "https://apps-apis.google.com/a/feeds/compliance/audit/mail/monitor/" . $domain .'/'. $username;
$req = new Google_Http_Request($url, 'POST');
$req->setPostBody($xml);
$token = json_decode($client->getAccessToken(), true);
$req->setRequestHeaders(
array(
'Content-Type'=> 'application/atom+xml; charset=utf-8',
'Authorization'=> 'Bearer ' . $token['access_token'] . '',
)
);
然而代码什么也没有返回。甚至没有像docmetation这样的http状态代码说: https://developers.google.com/admin-sdk/email-audit/#creating_a_new_email_monitor
然而,当我做的时候var_dump($req);
代码返回
object(Google_Http_Request)#52 (14) { ["batchHeaders":"Google_Http_Request":private]=> array(3) { ["Content-Type"]=> string(16) "application/http" ["Content-Transfer-Encoding"]=> string(6) "binary" ["MIME-Version"]=> string(3) "1.0" } ["queryParams":protected]=> array(0) { } ["requestMethod":protected]=> string(4) "POST" ["requestHeaders":protected]=> array(2) { ["content-type"]=> string(35) "application/atom+xml; charset=utf-8" ["authorization"]=> string(90) "Bearer ya29.tAC7zkWiQjV_KcSSQZhmUQGuXgXvN9LMVBERhflX2vs4qsfGGVQoBRIHSLGawsLLxYNPaZuqQgtKug" } ["baseComponent":protected]=> string(28) "https://apps-apis.google.com" ["path":protected]=> string(85) "/a/feeds/compliance/audit/mail/monitor/mydomain/abc" ["postBody":protected]=> string(597) " " ["userAgent":protected]=> NULL ["canGzip":protected]=> NULL ["responseHttpCode":protected]=> NULL ["responseHeaders":protected]=> NULL ["responseBody":protected]=> NULL ["expectedClass":protected]=> NULL ["accessKey"]=> NULL }
任何帮助??
答案 0 :(得分:0)
您的代码已创建请求,但尚未执行。您可以使用以下代码执行请求:
$resp = $client->execute($req);