Google Apps Email Audit API:POST请求,用于创建用户邮箱的监视器

时间:2015-07-09 11:27:15

标签: php email google-apps

使用 Google Apps电子邮件审核API 尝试创建一个监视器,将用户邮箱 rabbit@mydomain.com 中的所有字母复制到 auditor@mydomain.com 即可。在收到错误消息时:" prolog中不允许使用内容。"

 $url = 'https://apps-apis.google.com/a/feeds/compliance/audit/mail/monitor/mydomain.com/rabbit';

 $txtXML  = "<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>";
 $txtXML .= "<apps:property name='destUserName' value='auditor'/>";
 $txtXML .= "<apps:property name='endDate' value='2015-12-31 00:00'/>";
 $txtXML .= "</atom:entry>";

 $post_data = array( "xml" => $txtXML );

 $context = stream_context_create(
     array( 'http' => array(
              'method' => 'POST',
              'header'  => 'Content-length: '. strlen( $txtXML ) . PHP_EOL .
              'Content-type: application/atom+xml' . PHP_EOL . 
              'Authorization: Bearer ' . trim( $accessToken2v3 ) . PHP_EOL .
              '',
              'content' => http_build_query( $post_data )
              )
          )
 );

 $response = file_get_contents( $url, false, $context );

P.S。通过检查下一个文档来准备POST请求参数:

Google Apps Email Audit API开发人员指南:https://developers.google.com/admin-sdk/email-audit/

关于授权请求: https://developers.google.com/admin-sdk/email-audit/auth

将OAuth 2.0用于服务器到服务器应用程序: https://developers.google.com/identity/protocols/OAuth2ServiceAccount

0 个答案:

没有答案