getRequestToken(curPageUrl()); // Override callback page to this page /* Save temporary credentials to session. */ setcookie('oauth_token', $request_token['oauth_token'], time() + 120); setcookie('oauth_token_secret', $request_token['oauth_token_secret'], time() + 120); $token = $request_token['oauth_token']; session_regenerate_id(true); session_write_close(); /* If last connection failed don't display authorization link. */ switch ($connection->http_code) { case 200: /* Build authorize URL and redirect user to Twitter. */ $url = $connection->getAuthorizeURL($token); header('Location: ' . $url); break; default: /* Show notification if something went wrong. */ echo 'Could not connect to Twitter. Refresh the page or try again later.'; } } // Callback from Twitter API? If so, grab the long-lasting tokens if (isset($_REQUEST['oauth_token']) && isset($_REQUEST['oauth_verifier'])) { /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */ $connection = new TwitterOAuth($_COOKIE['consumer_key'], $_COOKIE['consumer_secret'], $_COOKIE['oauth_token'], $_COOKIE['oauth_token_secret']); /* Request long-term access tokens from twitter */ $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']); $oauth_token = $access_token['oauth_token']; $oauth_token_secret = $access_token['oauth_token_secret']; $screen_name = $access_token['screen_name']; session_destroy(); unset($_COOKIE); } ?> Convert Twitter Basic Authentication to OAuth Credentials

Convert Twitter Basic Authentication to OAuth Credentials

Screen Name

{$screen_name}

" . "

OAuth Token

{$oauth_token}

" . "

OAuth Secret

{$oauth_token_secret}

"; echo "

Back to the form

"; } else { // Display Form ?>

Prior Steps:

  1. Register an application with Twitter and note the Consumer Key/Secret.
  2. Log In as the Twitter User whose credentials you want to use.