PHP tutorials,a way to getting some thing new in web

Followers

Powered by Blogger.

Monday 4 August 2014

Login with Twitter Using PHP

No comments :
You can create your website with twitter login.You can now socialize your website on twitter.
here is code for it:

Please get twitter php sdk from:
https://github.com/abraham/twitteroauth

You can create your api on following url:

Please make sure your application have read/write permission.
https://dev.twitter.com/

To create Application and to learn twitter application After creating application you will get token and token secret.I am assuming that you all are know how to create twitter application,so not explaining here.



Code:

<?php
require("twitter/twitteroauth.php");
define('YOUR_CONSUMER_KEY', 'Twitter Key');
define('YOUR_CONSUMER_SECRET', 'Twitter Secret Key');
session_start();

$twitteroauth = new TwitterOAuth(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET);
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('http://yourwebsite.com/getTwitterData.php');

// Saving them into the session

$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];

// If everything goes well..
if ($twitteroauth->http_code == 200) {
    // Let's generate the URL and redirect
    $url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
    header('Location: ' . $url);
} else {
    // It's a bad idea to kill the script, but we've got to know when there's an error.
    die('Something wrong happened.');
}
?>

No comments :

Post a Comment