2013-10-02 46 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

如果您在創建或獲取方面遇到問題,您能澄清一下嗎? –

相關問題