first of all you need add new application to your twitter dev profile , and you need to specify the callback url , than if you're using a php mvc framework you need to go to your controller in twitter action you need to add the following:
// TWITTER APP KEYS $consumer_key = 'something you get from twitter dev'; $consumer_secret = 'other thing you get from twitter dev'; // CONNECTION TO THE TWITTER APP TO ASK FOR A REQUEST TOKEN $connection = new TwitterOAuth($consumer_key, $consumer_secret); $request_token = $connection->oauth("oauth/request_token", array( "oauth_callback" => "http://something/otherthing" )); // TAKING THE OAUTH TOKEN AND THE TOKEN SECRET AND PUTTING THEM IN COOKIES (NEEDED IN THE NEXT SCRIPT) $oauth_token = $request_token['oauth_token']; $token_secret = $request_token['oauth_token_secret'];
if you want you can put some variables in the cookies for a father use :
setcookie("token_secret", " ", time() - 3600); setcookie("token_secret", $token_secret, time() + 60 * 10); setcookie("oauth_token", " ", time() - 3600); setcookie("oauth_token", $oauth_token, time() + 60 * 10);
than you need to ask twitter to authorize your app
// GETTING THE URL FOR ASKING TWITTER TO AUTHORIZE THE APP WITH THE OAUTH TOKEN $url = $connection->url("oauth/authorize", array( "oauth_token" => $oauth_token ));
and the last thing you have to do is to render the url , basically this means that after the user give his approval we need to redirect him to another page where we could use more feature of twitter Oauth :
// REDIRECTING TO THE URL header('Location: ' . $url); }
please take a look abraham's twitter Oauth it's possible to upload it using composer.json:
{ "type": "package", "package": { "name": "abraham/twitteroauth", "description": "Twitter oauth", "version": "dev-dev", "keywords": ["Twitter API", "Twitter oAuth"], "license": "MIT", "authors": [ { "name": "Abraham Williams", "email": "[email protected]" } ], "require": { "php": ">=5.3.2" }, "autoload": { "files": ["twitteroauth/OAuth.php"] }, "source": { "type": "git", "url": "https://github.com/abraham/twitteroauth", "reference": "origin/dev" } }}]