views:

449

answers:

1

Any can tell me how to second time auto connect with twitter from my site.

I did... the following CODE

if(empty($outh_key_db)){
  $token=$_SESSION['oauth_token'] ;
  $outh_secr_db=$_SESSION['oauth_token_secret'];
  $con = mysql_connect("localhost","rathin","xxxxxxxxx");
  if (!$con)
  {
    die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("my_twtbook", $con);
  mysql_query("UPDATE register SET outh_key = '".$token."', outh_secr='".$outh_secr_db."' WHERE userid='".$loguser_email."'");

  mysql_close($con);

This code save the outh_token and outh_tk_secret to my DB. But on second time log in to my site I passed the 'outh_token and outh_tk_secret' in session with username.

The oauth not authenticate that....

Kindly suggest me.... to make aouth connect to twitter using oauth...if user once(1st time made the) connect twitter

+2  A: 

besides storing token and secret in your db, you should also store twitter id, so you can have a reference to it. Following flow should cover all (I think):

for each login

check if user already logged in (e.g. by checking if you already have the twitter id in session),

if user logged in, no need to go through twitter, just query the twitter id to get the token/secret or maybe you already have them in session.

if user not logged in yet, you will go through the same oauth steps to get twitter id, token and secrete. You code should then check if twitter id already exists in your db, if exists, update the record (just in case the token is changed - not sure if this will happen, e.g. when user revokes the permission since last visit). If it doesn't exist, insert new record and mark user' status as logged in(e.g. store twitter id somewhere (cookie, session))

Ji