401 error showing while requesting access token


#1

i am developing my first twitter application.i managed to get request_token and i successfully redirected after the twitter login.But my problem is i cant get the access token it showing 401 response.

session_start();
require_once('tmhOAuth.php');

$connection = new tmhOAuth(array(
'consumer_key' => '****',
'consumer_secret' => '****'

 ));

$connection->request('POST',$connection->url('oauth/request_token',""),array('oauth_callback' =>"http://www.123.in/twitter/twitterin.php"));

$result=$connection->extract_params($connection->response['response']);
$_SESSION['oauth_token']=$result['oauth_token'];
$_SESSION['oauth_token_secret']=$result['oauth_token_secret'];
$url='https://api.twitter.com/oauth/authenticate?oauth_token='.$result['oauth_token'];
header("Location:". $url);
this above code worked fine but at the redirect page twitter/twitterin.php

session_start();
require_once('tmhOAuth.php');

$connection = new tmhOAuth(array(
'consumer_key' => '****',
'consumer_secret' => '****'

 ));

$oauth_token=$_GET['oauth_token'];
$oauth_verifier=$_GET['oauth_verifier'];

 $connection->config["user_token"]=$_SESSION['oauth_token'];
 $connection->config["oauth_token_secret"]=$_SESSION['oauth_token_secret'];

$connection->request("POST", $connection-      >url("oauth/access_token",""),array("oauth_verifier"=>$oauth_verifier));
var_dump($connection->response);

I am getting 401 error as response

///

array(7) {
  ["raw"]=>
   string(1030) "HTTP/1.1 401 Unauthorized
Date: Fri, 21 Dec 2012 06:24:19 GMT
Status: 401 Unauthorized
Last-Modified: Fri, 21 Dec 2012 06:24:19 GMT
 Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
X-Transaction: a661a742c22b99be
Content-Type: text/html; charset=utf-8
X-MID: 9a96b4c8e27ef14ac86e72706ccd42c44121b507
X-Frame-Options: SAMEORIGIN
X-Runtime: 0.01811
Pragma: no-cache
Expires: Tue, 31 Mar 1981 05:00:00 GMT
Set-Cookie: k=10.35.51.118.1356071059097811; path=/; expires=Fri, 28-Dec-12 06:24:19        GMT; domain=.twitter.com
Set-Cookie: guest_id=v1%3A13560710591072098; domain=.twitter.com; path=/; expires=Sun,   21-Dec-2014 18:24:19 GMT
Set-Cookie:    _twitter_sess=BAh7CCIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoK     QHVzZWR7ADoHaWQiJThiOGE1OGQ3NTM4NTNlNTFmMmU1OGM3%250ANjliMDkxZjVkOg9jcmVhdGVkX2F0bCsIpD4ivDsB--c080621b27b01e102bd15dd85e14c984242127f8; domain=.twitter.com; path=/; HttpOnly
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 21
Server: tfe

 "
   ["headers"]=>
   array(18) {
    ["HTTP/1.1 401 Unauthorized"]=>
    string(0) ""
    ["Date"]=>
    string(29) "Fri, 21 Dec 2012 06:24:19 GMT"
    ["Status"]=>
    string(16) "401 Unauthorized"
    ["Last-Modified"]=>
    string(29) "Fri, 21 Dec 2012 06:24:19 GMT"
    ["Cache-Control"]=>
     string(62) "no-cache, no-store, must-revalidate, pre-check=0, post-check=0"
    ["X-Transaction"]=>
    string(16) "a661a742c22b99be"
    ["Content-Type"]=>
    string(24) "text/html; charset=utf-8"
    ["X-MID"]=>
    string(40) "9a96b4c8e27ef14ac86e72706ccd42c44121b507"
    ["X-Frame-Options"]=>
   string(10) "SAMEORIGIN"
    ["X-Runtime"]=> 
    string(7) "0.01811"
    ["Pragma"]=>
    string(8) "no-cache"
    ["Expires"]=>
   string(29) "Tue, 31 Mar 1981 05:00:00 GMT"
   ["Set-Cookie"]=>
   string(265)   "_twitter_sess=BAh7CCIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjo  KQHVzZWR7ADoHaWQiJThiOGE1OGQ3NTM4NTNlNTFmMmU1OGM3%250ANjliMDkxZjVkOg9jcmVhdGVkX2F0bCsIpD4ivDsB--c080621b27b01e102bd15dd85e14c984242127f8; domain=.twitter.com; path=/; HttpOnly"
    ["Vary"]=>
    string(15) "Accept-Encoding"
    ["Content-Encoding"]=>
   string(4) "gzip"
    ["Content-Length"]=>
    string(2) "21"
    ["Server"]=>
    string(3) "tfe"
    [""]=>
    string(0) ""
  }
  ["code"]=>
  int(401)
  ["response"]=>
   string(1) " "
   ["info"]=>
   array(22) {
    ["url"]=>
     string(42) "https://api.twitter.com/oauth/access_token"
     ["content_type"]=>
    string(24) "text/html; charset=utf-8"
    ["http_code"]=>
    int(401)
    ["header_size"]=>
    int(1029)
    ["request_size"]=>
    int(507)
    ["filetime"]=>
    int(-1)
    ["ssl_verify_result"]=>
    int(0)
    ["redirect_count"]=>
    int(0)
    ["total_time"]=>
    float(0.364576)
    ["namelookup_time"]=>
    float(0.002676)
    ["connect_time"]=>
    float(0.079689)
    ["pretransfer_time"]=>
    float(0.255704)
    ["size_upload"]=>
    float(0)
    ["size_download"]=>
    float(21)
    ["speed_download"]=>
    float(57)
    ["speed_upload"]=>
    float(0)
    ["download_content_length"]=>
    float(21)
    ["upload_content_length"]=>
    float(0)
    ["starttransfer_time"]=>
    float(0.364164)
    ["redirect_time"]=>
    float(0)
    ["certinfo"]=>
    array(0) {
    }
    ["request_header"]=>
    string(507) "POST /oauth/access_token HTTP/1.1
User-Agent: tmhOAuth 0.7.2+SSL - //github.com/themattharris/tmhOAuth
Host: api.twitter.com
Accept: */*
Accept-Encoding: deflate, gzip
Authorization: OAuth oauth_consumer_key="*****",
 oauth_nonce="****", oauth_signature="TzcIi0kOwhQ20xRMUQvYYl093B0%3D",         oauth_signature_method="HMAC-SHA1", oauth_timestamp="1356071058",     oauth_verifier="H2gFsotBlUPRBCdLu8ULpaV7fQVmSMGNmIaiWiYPERY", oauth_version="1.0"
Content-Length: 0
" } ["error"]=> string(0) "" ["errno"]=> int(0) }

what is the problem here?