Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For general OAuth principles to access Google, you might find <a href="http://googlecodesamples.com/oauth_playground/" rel="nofollow noreferrer">Google's OAuth playground</a> very useful (contacts are included there).</p> <p>This is a very basic example (using the php oauth pecl extension and simplexml, it just prints out the names of the 25 first contacts):</p> <pre><code>&lt;?php $cons_key="your consumer key"; $cons_sec="your consumer secret"; $callback="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; $req_token_url="https://www.google.com/accounts/OAuthGetRequestToken"; $auth_token_url="https://www.google.com/accounts/OAuthAuthorizeToken"; $acc_token_url="https://www.google.com/accounts/OAuthGetAccessToken"; $scope="https://www.google.com/m8/feeds/"; $scopes=urlencode($scope); $req_scope_token_url=$req_token_url."?scope=".$scopes; $endpoint="https://www.google.com/m8/feeds/contacts/default/full/"; session_start(); if(!isset($_GET['oauth_token']) &amp;&amp; $_SESSION['state']==1) $_SESSION['state'] = 0; try { $oauth = new OAuth($cons_key,$cons_sec); if(!isset($_GET['oauth_token']) &amp;&amp; !$_SESSION['state']) { $oauth = new OAuth($cons_key,$cons_sec); $oauth-&gt;setRequestEngine(OAUTH_REQENGINE_CURL); $request_token_info = $oauth-&gt;getRequestToken($req_scope_token_url,$callback); if(!empty($request_token_info)) { $_SESSION['token']=$request_token_info['oauth_token']; $_SESSION['secret']=$request_token_info['oauth_token_secret']; $_SESSION['state']=1; header('Location: '.$auth_token_url.'?oauth_token='.$_SESSION['token']); exit; } } else if($_SESSION['state']==1) { $oauth-&gt;setToken($_GET['oauth_token'],$_SESSION['secret']); $access_token_info = $oauth-&gt;getAccessToken($acc_token_url); $_SESSION['state'] = 2; $_SESSION['token'] = $access_token_info['oauth_token']; $_SESSION['secret'] = $access_token_info['oauth_token_secret']; } $oauth-&gt;fetch($endpoint); parseAtom($oauth-&gt;getLastResponse()); } catch(OAuthException $E) { print_r($E); } function parseAtom($atomstring) { global $oauth; $atom=simplexml_load_string($atomstring); foreach ($atom-&gt;entry as $entry) { print $entry-&gt;title.", "; } } ?&gt; </code></pre> <p>You can see the above code <s><a href="http://futtta.be/oauth/contacts.php" rel="nofollow noreferrer">in action here</a></s>.</p> <p>Installing (configuring) the oauth pecl extension can be tricky, you <a href="http://blog.futtta.be/2010/08/09/php-oauth-extension-trial-error-and-succes/" rel="nofollow noreferrer">may have to check your php.ini and/or specify a requestengine</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload