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

With Google Apps Email Audit API trying to create a monitor that will duplicate all the letters in the user's mailbox rabbit@mydomain.com to auditor@mydomain.com. In response to receiving the error message: "Content is not allowed in 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. Prepared for the POST request parameters by examining you next documentation:

Google Apps Email Audit API Developer's Guide: https://developers.google.com/admin-sdk/email-audit/

About Authorize Requests: https: //developers.google.com/admin-sdk/email-audit/auth

Using OAuth 2.0 for Server to Server Applications: https: //developers.google.com/identity/protocols/OAuth2ServiceAccount