Hello Marcelo,

Did you manage to resolve your issue? If not, please take a look at the
3-legged OAuth documentation:
  http://code.google.com/apis/gdata/docs/auth/oauth.html#Examples

Best,
Alain

On Mon, Jun 13, 2011 at 12:59 PM, Marcelo Iturbe
<[email protected]>wrote:

>
> The difference is in the  function (method) calls:
> OAuthRequest::from_consumer_and_token() and
> sign_request() where you need to send the token
>
>  Changes are in bold, this code is ugly but tested with 3-legged... (just
> change the app and user key/secrets)
>
>
> <?php
> require_once('oauth.php');
>  header("Content-type: text/html; charset=utf-8");
>
> $CONSUMER_KEY  = 'myDomain.com';
> $CONSUMER_SECRET  = 'MySecret';
>
> $csync = new Csync;
> $csync->init($CONSUMER_KEY,$CONSUMER_SECRET);
>         $retArr = $csync->GetUserContacts();
>         $xml_parser = xml_parser_create();
>         echo "contacts are <br>\n" . $retArr['xml'];
>
>
> class Csync
> {
>   public $consumer = null;
>   public function init($CONSUMER_KEY,$CONSUMER_SECRET)
>   {
>     $this->consumer = new OAuthConsumer($CONSUMER_KEY, $CONSUMER_SECRET,
> NULL);
>     if ($this->consumer == null)
>       return ("consumer not set<br/>");
>
>   }
>
>   public function GetUserContacts()
>   {
>     //group
>     $base_feed = 'https://www.google.com/m8/feeds/contacts/default/full';
>     $params = array('max-results' => 1);
>
>     $xmlStr = $this->execUrl($base_feed,$params,"GET");
>
>     return($xmlStr);
>
>   }
>   private function execUrl($base_feed,$params,$method, $xml=null)
>   {
>     if ($this->consumer == null)
>       return ("Call init first");
> *    $token->key = "1/AccessToken_J3Vp9kXyZcU";*
> *    $token->secret = "OHkk-AccessSecret";*
>
>     $request = OAuthRequest::from_consumer_and_token($this->consumer,*$token
> *, $method, $base_feed, $params);
>     // Sign the constructed OAuth request using HMAC-SHA1
>     $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(),
> $this->consumer,* $token*);
>     // Make signed OAuth request to the Contacts API server
>     $url = $base_feed . '?' . $this->implode_assoc('=', '&', $params);
>
>     $retArr = $this->send_request($request->get_normalized_http_method(),
> $url, $request->to_header(),$xml);
>     return($retArr);
>
>   }
>   private function implode_assoc($inner_glue, $outer_glue, $array) {
>     $output = array();
>     foreach($array as $key => $item) {
>       $output[] = $key . $inner_glue . urlencode($item);
>     }
>     return implode($outer_glue, $output);
>   }
>
>   private function send_request($http_method, $url, $auth_header=null,
> $postData=null)
>   {
>     $curl = curl_init($url);
>     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
>     curl_setopt($curl, CURLOPT_FAILONERROR, false);
>     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
>   curl_setopt($curl, CURLOPT_HEADER, 1 );
>   curl_setopt($curl, CURLINFO_HEADER_OUT, true);
>
> echo "header : $auth_header \n\n";
>     switch($http_method) {
>       case 'GET':
>         if ($auth_header) {
>         echo "INSIDE GET\n\n";
>           curl_setopt($curl, CURLOPT_HTTPHEADER,
> array($auth_header,'Content-Type: application/atom+xml', 'GData-Version:
> 2.0'));
>         }
>         break;
>       case 'POST':
>         curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:
> application/atom+xml',
>                                                      $auth_header));
>         curl_setopt($curl, CURLOPT_POST, 1);
>
>         curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
>         break;
>       case 'PUT':
>         curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:
> application/atom+xml',
>                                                      $auth_header));
>         curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $http_method);
>         curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
>         break;
>       case 'DELETE':
>         curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header));
>         curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $http_method);
>
>         break;
>     }
>     $response = curl_exec($curl);
>     print_r(curl_getinfo($curl, CURLINFO_HEADER_OUT ));
>     if (!$response) {
>       $response = curl_error($curl);
>     }
>     curl_close($curl);
>
>     $xml = strstr($response,"<");
>     $header = substr($response,0,strpos($response,"<"));
>     //echo $header . "\n";
>     flush();
>
>     return array('headers' => $header, 'xml' => $xml);
>
>   }
>
> }
>
> ?>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Google Contacts, Shared Contacts and User Profiles 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://code.google.com/apis/contacts/community/forum.html
>



-- 
Alain Vongsouvanh

-- 
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles 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://code.google.com/apis/contacts/community/forum.html

Reply via email to