After successfully connecting to Google Contacts API via php, how/what do I store in database to reconnect later? -


so here's deal.

i've connected google contact's api via php, stored in sessions, , retrieved list of contacts.

what want store necessary tokens in database, , retrieve them @ later time re-use them on same user. can't figure out information store... i've attempted storing every little item session database , reloading when try reconnect api, 1 error or because tokens aren't correct.

i imagine answer simple understands oauth - it's question of store.

code below:

<?php session_start();  include_once "../oauth-php/library/oauthstore.php"; include_once "../oauth-php/library/oauthrequester.php";  global $db;  $userid=$_session['userid'];  define("google_consumer_key", "website.com"); //  define("google_consumer_secret", "----------------------"); //   define("google_oauth_host", "https://www.google.com"); define("google_request_token_url", google_oauth_host . "/accounts/oauthgetrequesttoken"); define("google_authorize_url", google_oauth_host . "/accounts/oauthauthorizetoken"); define("google_access_token_url", google_oauth_host . "/accounts/oauthgetaccesstoken");  define('oauth_tmp_dir', function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : realpath($_env["tmp"]));  //  init oauthstore $options = array(  'consumer_key' => google_consumer_key,   'consumer_secret' => google_consumer_secret,  'server_uri' => google_oauth_host,  'request_token_uri' => google_request_token_url,  'authorize_uri' => google_authorize_url,  'access_token_uri' => google_access_token_url );  oauthstore::instance("session", $options);   try {  //  step 1:  if not have oauth token yet, go 1  if (empty($_get["oauth_token"]))  {   $getauthtokenparams = array('scope' =>     'https://www.google.com/m8/feeds/',    'xoauth_displayname' => 'my web app',    'oauth_callback' => 'http://website.com/google.php');    // request token   $tokenresultparams = oauthrequester::requestrequesttoken(google_consumer_key, 0, $getauthtokenparams);   //  redirect google authorization page, redirect   header("location: " . google_authorize_url . "?btmpl=mobile&oauth_token=" . $tokenresultparams['token']);  }  else {   //  step 2:  access token   $oauthtoken = $_get["oauth_token"];   $oauthverifier = $_get["oauth_verifier"];   $tokenresultparams = $_get;    //$db->query("update gmkeys set token='$oauthtoken', secrettoken='$oauthverifier'");   try {       oauthrequester::requestaccesstoken(google_consumer_key, $oauthtoken, 0, 'post', $_get);   }   catch (oauthexception2 $e)   {    var_dump($e);       // wrong oauth_token.       // be:       // 1. ok       // 2. not authorized       return;   }    // make request.   $request = new oauthrequester("https://www.google.com/m8/feeds/contacts/default/full?max-results=1000&group=http%3a%2f%2fwww.google.com%2fm8%2ffeeds%2fgroups%2fusernamehere%40gmail.com%2fbase%2f6", 'get', $tokenresultparams);     $result = $request->dorequest(0);   if ($result['code'] == 200)    {    $xml = new simplexmlelement($result['body']);    ...   }   else    {    echo 'error';   }  } } catch(oauthexception2 $e) {  echo "oauthexception:  " . $e->getmessage();  var_dump($e); } ?> 

the access_token , request_token strings


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -