Trever, Im still getting this (Token invalid - AuthSub token has wrong
scope, Error 401) error. Here's the process.

I'm trying to create a function that will post my xml data to google.
This particular function is first being tested for creating a new
google calendar.

-----------------------------------------------
Web resources used:
http://framework.zend.com/manual/en/zend.gdata.authsub.html
http://code.google.com/apis/accounts/docs/AuthSub.html
http://code.google.com/apis/gdata/auth.html
http://code.google.com/apis/calendar/docs/2.0/developers_guide_protocol.html#Auth

-----------------------------------------------
Variables being sent to function:
-----------------------------------------------
                $data        = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
                                <entry xmlns='http://www.w3.org/2005/Atom'
                                 xmlns:gd='http://schemas.google.com/g/2005'
                                 
xmlns:gCal='http://schemas.google.com/gCal/2005'>
                                <title type='text'>Little League 
Schedule</title>
                                <summary type='text'>This calendar contains the 
practice
                                schedule and game times.</summary>
                                <gCal:timezone 
value='America/Los_Angeles'></gCal:timezone>
                                <gCal:hidden value='false'></gCal:hidden>
                                <gCal:color value='#2952A3'></gCal:color>
                                <gd:where rel='' label='' 
valueString='Oakland'></gd:where>
                                </entry>";


-----------------------------------------------
Heres the function that I'm building
---------------------------------------------
        function do_post_request($data,
         $url ='http://www.google.com/calendar/feeds/default/
owncalendars/full'){
                //  setting the header
                $ContentLength           = strlen($data);
                $header                          = "POST $url HTTP/1.0 \r\n";
                $header                         .= "Content-type: 
application/atom+xml \r\n";
                $header                         .= "Content-length: 
".$ContentLength." \r\n";
                //$header                       .= "Authorization: GoogleLogin 
auth=".$GLOBALS
['googleToken']['Auth'].' \r\n'; // AuthUserToken
                $header                         .= "Authorization: AuthSub 
token=".$_SESSION
['cal_token']." \r\n";  //Token invalid - AuthSub token has wrong scope
                $header                         .= "Cache-Control: no-cache ";
                $header                         .= "Transfer-Encoding: Chunked 
\r\n";
                $header                         .= "Connection: close \r\n\r\n";
                $header                         .= $data;

                // sending the xml request
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_TIMEOUT, 4);
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);

                $results = curl_exec($ch);

                if(curl_errno($ch)) {
                        print curl_error($ch);
                } else {
                        curl_close($ch);
                        return $results;
                }

        }



-----------------------------------------------
I've basically been receiving this error
---------------------------------------------

Token invalid - AuthSub token has wrong scope
Error 401


-----------------------------------------------
I've tested the following methods to catch a valid auth token
---------------------------------------------

                $my_calendar = 
'http://www.google.com/calendar/feeds/default/private/
full';

                if (!isset($_SESSION['cal_token'])) {
                        if (isset($_GET['token'])) {
                                // You can convert the single-use token to a 
session token.
                                $session_token =
                                        
Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
                                // Store the session token in our session.
                                $_SESSION['cal_token'] = $session_token;
                        } else {
                                // Display link to generate single-use token
                                $googleUri = 
Zend_Gdata_AuthSub::getAuthSubTokenUri(
                                        'http://'. $_SERVER['SERVER_NAME'] . 
$_SERVER['REQUEST_URI'],
                                        $my_calendar, 0, 1);
                                echo "Click <a href='$googleUri'>here</a> " .
                                         "to authorize this application.";
                                exit();
                        }
                }

---------------------
using $_GET['token'] and $_SESSION['cal_token'] return the same (Token
invalid - AuthSub token has wrong scope, Error 401) error.

This script did display the link in order for me to register my web
application with google. I did the registration and the link no longer
displays.
------------------------
I've also hacked the Zend/Gdata/ClientLogin.php file to return the
Auth, SID and LSID variables using a global variable. I've tested the
Auth token return by Zend's gdata login process and I still receive
the same error. Starting at line 154 of Zend/Gdata/ClientLogin.php

I'm using this client login when I post events to the calendar.
currently my script is posting approx. 200 events to the google
calendar per day. So I know that this is working for Zend.


        if ($response->getStatus() == 200) {
            $client = new Zend_Gdata_HttpClient();
            $client->setClientLoginToken($goog_resp['Auth']);

                        
//------------------------------------------------------------------
                        // simple hack here
                        global $googleToken;
                        $GLOBALS['googleToken'] = $goog_resp;

            $useragent = $source . ' Zend_Framework_Gdata/' .
Zend_Version::VERSION;
            $client->setConfig(array(
                    'strictredirects' => true,
                    'useragent' => $useragent
                )
            );
            return $client;







------------------------
I'm running out of options here...  Can you see anything that I'm
missing?
Thanks in advance


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Calendar Data API" 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-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to