Hi,

I see that you have used the following header incorrectly:
"Authorization: GoogleLogin auth: " + $authkey

It should work if you replace it with:
"Authorization: GoogleLogin auth=" . $authkey

Notice the '=' after 'auth' and string concat with dot.

-Anirudh
On Jan 6, 1:06 am, andy <[email protected]> wrote:
> I'm working on a test script to work with out Google Apps account, but
> I keep getting weird error:
>
> Authorization required
> Error 401
>
> I know my account works, because I have a VB.NET program that works
> and pulls down account information.  However, when I use the code
> below, I gt the above error in HTML format.  Can someone tell me what
> I'm doing wrong?  Thanks!
>
> --- CODE BLOCK ---
>
> <?php
>
> $domain = "domain.com";
> $auth_url = "https://www.google.com/accounts/ClientLogin";;
> $list_url = "https://apps-apis.google.com/a/feeds/"; . $domain . "/user/
> 2.0";
>
> $user = "[email protected]";
> $pass = "xxxxxx";
>
> $resp = get_auth($auth_url, $user, $pass);
>
> if (substr($resp, 0, 3) != "SID")
> {
>     echo("Error.");
>     die;
>
> }
>
> $responses = preg_split("/\n/", $resp);
>
> $params = array();
>
> foreach($responses as $response)
> {
>     $d = preg_split("/=/", $response, 2);
>
>     if (strlen($d[0]) > 0)
>     {
>         $params[$d[0]] = $d[1];
>     }
>
> }
>
> echo($params['Auth']);
> echo("\n");
> echo(get_list($list_url, $params['Auth']));
>
> function get_auth($url, $user, $pass)
> {
>     $data = "Email=" . urlencode($user) . "&Passwd=" . urlencode
> ($pass) .
>             "&accountType=HOSTED&service=apps";
>
>     echo($data."\n");
>
>     $ch = curl_init($url);
>
>     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
>     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
>     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  false);
>     curl_setopt($ch, CURLOPT_POST, true);
>     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
>
>     $r = curl_exec($ch);
>
>     curl_close($ch);
>
>     return $r;
>
> }
>
> function get_list($url, $authkey)
> {
>     $str = array(
>         "Content-type: application/atom+xml",
>         "Authorization: GoogleLogin auth: " + $authkey
>     );
>
>     $ch = curl_init($url);
>
>     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
>     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
>     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  false);
>     curl_setopt($ch, CURLOPT_HTTPHEADER, $str);
>
>     $r = curl_exec($ch);
>
>     curl_close($ch);
>
>     return $r;
>
> }
>
> ?>
>
> --- CODE BLOCK ---
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to