2013-10-02 47 views
0

我使用cURL通过Google API从用户获取所有电子邮件。正在关注https://developers.google.com/admin-sdk/email-audit/#retrieving_all_email_monitors_of_a_source_userCURL - 从Google API检索所有电子邮件

根据本教程,服务器返回'201 Created'状态码成功。但是,我的结果返回'200 OK'代码。

这里是代码授权

$data = array(
'accountType' => 'HOSTED_OR_GOOGLE', 
'Email' => 'myEmail', 
'Passwd' => 'myPassword', 

'source'=>'PHP-cUrl-Example', 
'service'=>'apps'); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin"); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
$response = curl_exec($ch); 

这里是代码检索源用户的所有电子邮件监控

preg_match("/Auth=([a-z0-9_-]+)/i", $response, $matches); 
$auth = $matches[1]; 

$header = array('Content-Type: application/atom+xml; charset=utf-8', 
      'Authorization: GoogleLogin auth='.trim($auth), 
    ); 
$url_email ="https://apps-apis.google.com/a/feeds/compliance/audit/mail/monitor/mydomain/username"; 
curl_setopt($ch, CURLOPT_URL, $url_email); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POST, FALSE); 
curl_setopt($ch, CURLOPT_HEADER, false); 
$response = curl_exec($ch); 
$response = simplexml_load_string($response); 
curl_close($ch); 

print_r($response); 

帮我请?

+0

当您检索所有电子邮件监视器时,结果如何?你在那里创建的那个? – Emily

+0

@EmilyLam:返回所有电子邮件监视器都没有条目元素的AtomPub订阅源 –

回答

0

该API允许你request the status of a single export request与一个URL:

https://apps-apis.google.com/a/feeds/compliance/audit/mail/export/ {域名}/{源用户名}/{邮箱的requestId}

all requests across the domain用的请求:

https://apps-apis.google.com/a/feeds/compliance/audit/mail/export/ {domain name}?fromDate = {fromDate}

没有操作来检索给定用户的所有请求的状态,就像您正在尝试执行的操作。

我建议您确认您已通过使用GAMcreate the request成功创建了审核请求。 GAM会告诉你成功的请求ID。然后,您可以尝试使用您的代码获取单个请求的结果。

+0

我的意思是,尽管我验证了成功,但响应请求没有返回数据。 –

+0

如果您在创建或获取方面遇到问题,您能澄清一下吗? –

相关问题