Today, We want to share with you PHP CodeIgniter Twitter Login Steps.In this post we will show you How to Use the Twitter API with Codeigniter, hear for Login with Twitter in PHP CodeIgniter full code we will give you demo and example for implement.In this post, we will learn about PHP Twitter Login And Integration in PHP Website Tutorial with an example.
PHP CodeIgniter Twitter Login Steps
There are the Following The simple About PHP CodeIgniter Twitter Login Steps Full Information With Example and source code.
As I will cover this Post with live Working example to develop Login With Twitter PHP CodeIgniter, so the Integrate Twitter Login in CodeIgnitor for this example is following below.
How to Auto Post on Twitter using PHP API
Step 1: Download twitter PHP CodeIgnitor library
Free Download twitter PHP library
First of all You open your terminal or CDM and run this Commads and free to fill Download Twitter Library in PHP CodeIgnitor
composer require abraham/twitteroauth
Step 2 : Twitter Login config
application/config/constant.php
define("Consumer_Key", "jayPakaiFod896556"); define("Consumer_Secret", "DSPpakajayGonsimp8598Siisksjt");
Step 3: Twitter Authentication
application/libraries/TwitterAuth.php
CI =& get_instance(); $this->CI->load->library('session'); $this->connection= new TwitterOAuth(Consumer_Key, Consumer_Secret); } public function getLogin(){ $this->request_token = $this->connection->oauth("oauth/request_token", array("oauth_callback" => base_url()."Dashboardblog/twitterResponse")); // print_r($this->request_token); $_SESSION['oauth_token'] = $this->request_token['oauth_token']; $_SESSION['oauth_token_secret'] = $this->request_token['oauth_token_secret']; $url = $this->connection->url("oauth/authorize", array("oauth_token" => $this->request_token['oauth_token'])); $this->CI->session->set_userdata('oauth_token', $this->request_token['oauth_token']); $this->CI->session->set_userdata('oauth_token_secret',$this->request_token['oauth_token_secret']); redirect($this->connection->url('oauth/authorize', array('oauth_token' => $this->request_token['oauth_token']), 'refresh')); } public function checkAuth(){ $this->connection = new TwitterOAuth(Consumer_Key, Consumer_Secret, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); $this->access_token = $this->connection->oauth('oauth/access_token', array('oauth_verifier' => $_REQUEST['oauth_verifier'], 'oauth_token'=> $_GET['oauth_token'])); $this->connection = new TwitterOAuth(Consumer_Key, Consumer_Secret, $this->access_token['oauth_token'], $this->access_token['oauth_token_secret']); $this->user_info = $this->connection->get('account/verify_credentials'); return $this->user_info; } }
Step 4 : Create View Files
display twitter login button.
function index(){ $this->load->view('twitter_auth'); }
application/views/twitter_auth.php
www.pakainfo.com - Twitter Login using PHP
How to Send Twitter Automatically Tweets with PHP
Step 5 : PHP codeignitor twitterAuth in controller
load TwitterAuth Library in codeignitor
public function twitterAuth(){ $this->load->library('TwitterAuth'); $this->twitterauth->getLogin(); }
public function twitterResponse(){ $this->load->library('TwitterAuth'); $this->load->model('User_model'); $twitter_data = $this->twitterauth->checkAuth(); $res = $this->User_model->insert_userdata($twitter_data); if($res){ $userdata = array('id'=>$res->id,'firstname'=>$res->firstname,'lastname'=>$res->lastname,'email'=>$res->email,'password'=>$res->password,'user_type'=>$res->user_type); $this->session->set_userdata($userdata); redirect(base_url('Dashboard/index')); }
Twitter Login using TwitterOAuth and PHP
application/models/User_model.php
function check_tuser($data){ $check = $this->ConfirmTwiterUsers($data->id); $users_data = array('twitter_id'=>$data->id, 'firstname'=>$data->screen_name, 'location'=>$data->location, 'profile_pic'=>$data->profile_image_url, ); if(!empty($check) && count($check) > 0 ){ $this->db->where('id',$check->id); $this->db->update('signup',$users_data); return $check; }else{ $this->db->insert('signup',$users_data); return $this->ConfirmTwiterUsers($this->db->insert_id()); } } function ConfirmTwiterUsers($id){ $this->db->select('*'); $this->db->from("signup"); $this->db->where('twitter_id',$id); $qry = $this->db->get(); return $qry->row(); }
Angular 6 CRUD Operations Application Tutorials
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about PHP CodeIgniter Twitter Login Steps.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.