title: Abraham Williams Twitter OAuth 303 Error
body: <p>EDIT:
  I'm sorry for making this thread as I've figured out the problem. </p>
  
  <p>Here's what happened:
  First, I noticed that the URL being sent lacked a "/" between .com and account/verify_credentials. When I updated that, I got a 404 error. Then I looked at the twitteroauth.php and I noticed that the top one:</p>
  
  <pre><code>/* Set up the API root URL. */
  public $host = "https://api.twitter.com/1/";
  //  public $host = "https://dev.twitter.com";
  </code></pre>
  
  <p>was commented out. I uncommented it, and commented out the lower one (which I'm guessing is no defunct or not used?) and now it works perfectly fine!</p>
  
  <p>Thanks everybody, and thanks Mr. Williams for a great Oauth library!</p>
  
  <hr>
  
  <p>I've been implementing Abraham Williams Twitter OAuth library and it's been going well so far until I tried to do something with it after connecting to Twitter. That's when I was getting a 303 HTTP code. I then changed my implementation to the way he implements it on his github site, and I still get the same issue. Does anyone have an idea of what's happening?</p>
  
  <p>apitest.php is where the problem occurs, where the $connection variable has a 303 HTTP code. The corresponding $connection variables in redirect.php and callback.php both return a 200. By the way, all of the files are in the same directory.</p>
  
  <p>Here's the code:</p>
  
  <p>connect.php (The HTML on this page has a button that goes to redirect.php)</p>
  
  <pre><code>&lt;?php
  /**
  * @file
  * Check if consumer token is set and if so send user to get a request token.
  */
  
  /**
  * Exit with an error message if the CONSUMER_KEY or CONSUMER_SECRET is not defined.
  */
  require_once('twitconfig.php');
  if (CONSUMER_KEY === '' || CONSUMER_SECRET === '') {
    echo 'A consumer key and secret are required.';
    exit();
  }
  
  ?&gt;
  </code></pre>
  
  <p>redirect.php</p>
  
  <pre><code>&lt;?php
  
  /* Start session and load library. */
  session_start();
  require_once('twitteroauth.php');
  require_once('twitconfig.php');
  
  /* Build TwitterOAuth object with client credentials. */
  $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
  
  /* Get temporary credentials. */
  $request_token = $connection-&gt;getRequestToken(OAUTH_CALLBACK);
  
  /* Save temporary credentials to session. */
  $_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
  $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
  
  /* If last connection failed don't display authorization link. */
  switch ($connection-&gt;http_code) {
    case 200:
      /* Build authorize URL and redirect user to Twitter. */
      $url = $connection-&gt;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.';
  }
  
  ?&gt;
  </code></pre>
  
  <p>callback.php</p>
  
  <pre><code>&lt;?php
  
  /**
   * @file
   * Take the user when they return from Twitter. Get access tokens.
   * Verify credentials and redirect to based on response from Twitter.
   */
  
  /* Start session and load lib */
  session_start();
  require_once('twitteroauth.php');
  require_once('twitconfig.php');
  
  /* If the oauth_token is old redirect to the connect page. */
  if (isset($_REQUEST['oauth_token']) &amp;&amp; $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
    $_SESSION['oauth_status'] = 'oldtoken';
    header('Location: ./clearsessions.php');
  }
  
  /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
  $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
  
  /* Request access tokens from twitter */
  $access_token = $connection-&gt;getAccessToken($_REQUEST['oauth_verifier']);
  
  /* Save the access tokens. Normally these would be saved in a database for future use. */
  $_SESSION['access_token'] = $access_token;
  
  /* Remove no longer needed request tokens */
  unset($_SESSION['oauth_token']);
  unset($_SESSION['oauth_token_secret']);
  
  
  /* If HTTP response is 200 continue otherwise send to connect page to retry */
  if (200 == $connection-&gt;http_code) {
    /* The user has been verified and the access tokens can be saved for future use */
    $_SESSION['status'] = 'verified';
    header('Location: ./apitest.php');
  } else {
    /* Save HTTP status for error dialog on connnect page.*/
    header('Location: ./clearsessions.php');
  }
  
  ?&gt;
  </code></pre>
  
  <p>apitest.php (where the problem is seen via a print_r)</p>
  
  <pre><code>&lt;?php
  
  session_start();
  require_once('twitteroauth.php');
  require_once('twitconfig.php');
  
  if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
      header('Location: ./clearsessions.php');
  }
  
  /* Get user access tokens out of the session. */
  $access_token = $_SESSION['access_token'];
  
  /* Create a TwitterOauth object with consumer/user tokens. */
  $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
  
  
  /* Get logged in user to help with tests. */
  $user = $connection-&gt;get('account/verify_credentials');
  
  print_r($connection);
  
  print_r($_SESSION);
  
  ?&gt;
  </code></pre>
  
  <p>The output of the first print statement is:</p>
  
  <pre><code>TwitterOAuth Object ( 
  [http_code] =&gt; 303 
  [url] =&gt; https://dev.twitter.comaccount/verify_credentials.json?oauth_consumer_key=UoXXKdfnVHh2fYD8Csw&amp;oauth_nonce=09bc369393a8eab3a1dc36eaa6230b45&amp;oauth_signature=pe5dYtYq%2FvlGb0c%2BnRR%2BQAXI0Ec%3D&amp;oauth_signature_method=HMAC-SHA1&amp;oauth_timestamp=1314249851&amp;oauth_token=351699791-F6stFFk81poF8ooORgLLxaE2cpSdDT2Vr0Tz9yJm&amp;oauth_version=1.0 
  [host] =&gt; https://dev.twitter.com 
  [timeout] =&gt; 30 
  [connecttimeout] =&gt; 30 
  [ssl_verifypeer] =&gt; 
  [format] =&gt; json 
  [decode_json] =&gt; 1 
  [http_info] =&gt; Array ( [url] =&gt; https://dev.twitter.comaccount/verify_credentials.json?oauth_consumer_key=UoXXKdfnVHh2fYD8Csw&amp;oauth_nonce=09bc369393a8eab3a1dc36eaa6230b45&amp;oauth_signature=pe5dYtYq%2FvlGb0c%2BnRR%2BQAXI0Ec%3D&amp;oauth_signature_method=HMAC-SHA1&amp;oauth_timestamp=1314249851&amp;oauth_token=351699791-F6stFFk81poF8ooORgLLxaE2cpSdDT2Vr0Tz9yJm&amp;oauth_version=1.0 
  [content_type] =&gt; 
  [http_code] =&gt; 303 
  [header_size] =&gt; 565 
  [request_size] =&gt; 401 
  [filetime] =&gt; -1 
  [ssl_verify_result] =&gt; 1 
  [redirect_count] =&gt; 0 
  [total_time] =&gt; 0.053773 
  [namelookup_time] =&gt; 0.003355 
  [connect_time] =&gt; 0.006399 
  [pretransfer_time] =&gt; 0.047636 
  [size_upload] =&gt; 0 
  [size_download] =&gt; 0 
  [speed_download] =&gt; 0 
  [speed_upload] =&gt; 0 
  [download_content_length] =&gt; 0 
  [upload_content_length] =&gt; 0 
  [starttransfer_time] =&gt; 0.053629 
  [redirect_time] =&gt; 0 
  [certinfo] =&gt; Array ( ) ) 
  [useragent] =&gt; TwitterOAuth v0.2.0-beta2 
  [sha1_method] =&gt; OAuthSignatureMethod_HMAC_SHA1 Object ( ) 
  [consumer] =&gt; OAuthConsumer Object ( [key] =&gt; UoXXKdfnVHh2fYD8Csw [secret] =&gt; SyKfxRorvUs6THwj5l26TGEkFOCGf1vG86N7PoS97o [callback_url] =&gt; ) [token] =&gt; OAuthConsumer Object ( [key] =&gt; 351699791-F6stFFk81poF8ooORgLLxaE2cpSdDT2Vr0Tz9yJm [secret] =&gt; q8fHaTaFvOUL8XKYX89LSgubr2fSl1xHBUAi8MUqIc [callback_url] =&gt; ) 
  
  [http_header] =&gt; Array ( [location] =&gt; http://guide.a.id.opendns.com/?url=dev%2Etwitter%2Ecomaccount%2Fverify%5Fcredentials%2Ejson%3Foauth%5Fconsumer%5Fkey%3DUoXXKdfnVHh2fYD8Csw%26oauth%5Fnonce%3D09bc369393a8eab3a1dc36eaa6230b45%26oauth%5Fsignature%3Dpe5dYtYq%252FvlGb0c%252BnRR%252BQAXI0Ec%253D%26oauth%5Fsignature%5Fmethod%3DHMAC%2DSHA1%26oauth%5Ftimestamp%3D1314249851%26oauth%5Ftoken%3D351699791%2DF6stFFk81poF8ooORgLLxaE2cpSdDT2Vr0Tz9yJm%26oauth%5Fversion%3D1%2E0 
  [content_length] =&gt; 0 
  [connection] =&gt; close 
  [date] =&gt; Thu, 25 Aug 2011 05:24:50 GMT 
  [server] =&gt; OpenDNS Guide ) ) 
  </code></pre>
  
  <p>The output of the second print statement is:</p>
  
  <pre><code>Array ( 
  [access_token] =&gt; Array ( 
  [oauth_token] =&gt; 351699791-F6stFFk81poF8ooORgLLxaE2cpSdDT2Vr0Tz9yJm 
  [oauth_token_secret] =&gt; q8fHaTaFvOUL8XKYX89LSgubr2fSl1xHBUAi8MUqIc 
  [user_id] =&gt; 351699791 
  [screen_name] =&gt; jibjib21 ) 
  [status] =&gt; verified ) 
  </code></pre>
  
  <p>Does anyone have an idea of what's going on with this 303 error and how to resolve it? Any help would be greatly appreciated. Thanks!</p>