Hi Pete,
You should definitely use "www.google.com" instead of the IP as this
is the root cause of your 302 error. Also, can you make sure all the
variables that you pass into "$data" do not have any newline
characters and the report date is in yyyy-MM-dd format (i.e.
2008-01-01 but not 2008-1-1)? The SID should just work if your code
obtains the right one and it is not truncated. I was able to obtain
reports with the following code (you may need to reformat some long
lines as they will be split to multiple lines by Google Groups):
<?php
function create_reports($token, $domain = "your domain", $date =
"2008-11-20", $page = "1", $reportType="daily",
$reportName="activity")
{
//Variables
$data = <<< END
<?xml version="1.0" encoding="UTF-8"?>
<rest xmlns="google:accounts:rest:protocol"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<type>Report</type>
<token>{$token}</token>
<domain>{$domain}</domain>
<date>{$date}</date>
<page>{$page}</page>
<reportType>{$reportType}</reportType>
<reportName>{$reportName}</reportName>
</rest>
END;
//$data = urlencode($data);
$host="www.google.com";
$method="post";
$path="/hosted/services/v1.0/reports/ReportingData";
$method = strtoupper($method);
//sending raw HTTP headers
$fp = fsockopen("ssl://".$host, 443);
fputs($fp, "$method $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/atom+xml\r\n");
fputs($fp, "Content-Length: " . strlen($data) . "\r
\n");
fputs($fp, "Connection: Close\r\n\r\n");
fputs($fp, $data);
//getting the reply
while (!feof($fp))
{
$buf .= fgets($fp);
}
echo $buf;
fclose($fp);
}
create_reports("your SID");
?>
Please let me know if you can get it to work after making all
precautions above.
Thanks,
--Tony
On Dec 1, 2:31 pm, Pete <[EMAIL PROTECTED]> wrote:
> Hi Tony,
>
> This is still causing trouble:
> 1.
> even using
> $data = '<?xml version="1.0" encoding="UTF-8"?><rest
> xmlns="google:accounts:rest:protocol"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
> "><type>Report</type><token>{$token}</token><domain>{$domain}</
> domain><date>{$date}</date><page>{$page}</page><reportType>
> {$reportType}</reportType><reportName>{$reportName}</reportName></
> rest>';
> gives me the same 302 error
>
> If i mangle the XML the same 302 error still appears, suggesting it is
> not dealt with before bailing
>
> 2.
> If I usewww.google.cominstead of the $host="66.249.91.99" address I
> get:
>
> Content-length: 328 HTTP/1.1 200 OK Content-Type: text/xml;
> charset=UTF-8 Date: Mon, 01 Dec 2008 22:27:36 GMT X-Content-Type-
> Options: nosniff Expires: Mon, 01 Dec 2008 22:27:36 GMT Cache-Control:
> private, max-age=0 Content-Length: 311 Server: GFE/1.3 Connection:
> Close Failure(2001)MalformedRequest(1004)No extended message available
> for this error.
>
> 3. I'm certain I am using the SID and not the AUTH, it is gathered
> from another file in realtime. Is there any way to check that this
> SID works?
>
> Thanks
>
> Pete
>
> On 28 Nov, 21:46, "Tony (Google)" <[EMAIL PROTECTED]> wrote:
>
> > Hi Pete,
>
> > I did some troubleshooting for you. Please fix the following:
>
> > 1. Please strip all the spaces in front of " <?xml
> > version="1.0" encoding="UTF-8"?>".
> > 2. You can replace the IP address back withwww.google.com
> > 3. Make sure you use the right authentication token. (i.e. the
> > SID=DQAAAGA... one, not Auth=DQAAAGA...)
>
> > I hope this helps.
>
> > Thanks,
>
> > --Tony
>
> > On Nov 28, 5:49 am, Pete <[EMAIL PROTECTED]> wrote:
>
> > > Actually my fix was a dead end, you can change HTTP to CABBAGES and it
> > > still spits out the same error. The error is still with the 302. Any
> > > ideas, web searching isn't being productive.
>
> > > Thanks
>
> > > Pete
>
> > > On Nov 27, 6:12 pm, Pete <[EMAIL PROTECTED]> wrote:
>
> > > > Nearly fixed. It needed a HTTPS instead of HTTP, now it is saying:
>
> > > > POST requests require a Content-length header.
>
> > > > though this is clearly present below...
>
> > > > Any ideas?
>
> > > > On Nov 27, 5:54 pm, Pete <[EMAIL PROTECTED]> wrote:
>
> > > > > I am writing some code for our google site to check on mail account
> > > > > usage. I have extracted the Google API token and pass it to this
> > > > > function. I realise there is a PHP example out there using CURL, the
> > > > > server we are using doesn't have CURL so I'm trying to hard code it.
> > > > > What am I doing wrong ?
>
> > > > > function create_reports($token, $domain = "teachfirst.org.uk", $date =
> > > > > "2008-11-20", $page = "1", $reportType="daily",
> > > > > $reportName="activity")
> > > > > {
> > > > > //Variables
> > > > > $data = <<< END
> > > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > > <rest xmlns="google:accounts:rest:protocol"
> > > > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> > > > > <type>Report</type>
> > > > > <token>{$token}</token>
> > > > > <domain>{$domain}</domain>
> > > > > <date>{$date}</date>
> > > > > <page>{$page}</page>
> > > > > <reportType>{$reportType}</reportType>
> > > > > <reportName>{$reportName}</reportName>
> > > > > </rest>
> > > > > END;
> > > > > $host="66.249.91.99";
> > > > > //thatswww.google.comincasetheDNSisgiving
> > > > > issues
> > > > > $method="post";
> > > > > $path="/hosted/services/v1.0/reports/ReportingData";
> > > > > $method = strtoupper($method);
> > > > > //sending raw HTTP headers
> > > > > $fp = fsockopen('ssl://'.$host, 443);
> > > > > fputs($fp, "$method $path HTTP/1.1\r\n");
> > > > > fputs($fp, "Host: $host\r\n");
> > > > > fputs($fp, "Content-type: application/atom+xml\r\n");
> > > > > fputs($fp, "Content-Length: " . strlen($data) .
> > > > > "\r\n");
> > > > > fputs($fp, "Connection: Close\r\n\r\n");
> > > > > fputs($fp, $data);
> > > > > //getting the reply
> > > > > while (!feof($fp))
> > > > > {
> > > > > $buf .=fgets($fp);
> > > > > }
> > > > > echo $buf;
> > > > > fclose($fp);
>
> > > > > }
>
> > > > > ERROR GIVEN
> > > > > #############
> > > > > HTTP/1.1 302 Found Location:http://www.google.comDate:Thu, 27 Nov
> > > > > 2008 17:14:52 GMT Content-Type: text/html; charset=UTF-8 Server: GFE/
> > > > > 1.3 Content-Length: 218 Connection: Close
>
> > > > > 302 Moved
> > > > > The document has moved here
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Apps APIs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-apps-apis?hl=en
-~----------~----~----~----~------~----~------~--~---