Twitter OAuth (PHP): Need good, basic example to get started

后端 未结 5 1142
醉话见心
醉话见心 2020-12-07 16:57

Using Facebook\'s PHP SDK, I was able to get Facebook login working pretty quickly on my website. They simply set a $user variable that can be accessed very eas

5条回答
  •  难免孤独
    2020-12-07 17:27

    this one is the basic example of getting the url for authorization and then fetching the user basic info when once u get back from twitter

     $_GET['oauth_verifier'],"oauth_token"=>$_GET['oauth_token']);
      $access_token = $connection->oauth("oauth/access_token", $params);
      //now again create new instance using updated return oauth_token and oauth_token_secret because old one expired if u dont u this u will also get token expired error
      $connection = new TwitterOAuth($consumer_key, $consumer_secret,
      $access_token['oauth_token'],$access_token['oauth_token_secret']);
      $content = $connection->get("account/verify_credentials");
      print_r($content);
    }
    else{
      // main startup code
      $consumer_key = 'your consumer key';
      $consumer_secret = 'your secret key';
      //this code will return your valid url which u can use in iframe src to popup or can directly view the page as its happening in this example
    
      $connection = new TwitterOAuth($consumer_key, $consumer_secret);
      $temporary_credentials = $connection->oauth('oauth/request_token', array("oauth_callback" =>'http://dev.crm.alifca.com/twitter/index.php'));
      $_SESSION['oauth_token']=$temporary_credentials['oauth_token'];       $_SESSION['oauth_token_secret']=$temporary_credentials['oauth_token_secret'];$url = $connection->url("oauth/authorize", array("oauth_token" => $temporary_credentials['oauth_token']));
    // REDIRECTING TO THE URL
      header('Location: ' . $url); 
    }
    ?>
    

提交回复
热议问题