twitter oauth :geting undefined index: oauth_token

2019-04-02 17:41发布

Hi am trying to post tweets using oauth (PHP)

i created the application in my twitter account ,

i executed some open source script but that produce the below error,

Notice: Undefined index: oauth_token_secret in

How to fix this issue

my snippet

require_once('twitterOAuth/twitterOAuth.php');
require_once('twitterOAuth/OAuth.php');


$consumer_key='q3fsdfsdfsdw';
$consumer_secret='rfsdfsdfsdfsdfdsfsdL';
$request_token='http://twitter.com/oauth/request_token';
$request_token_secret='5454545';
$oauth = new TwitterOAuth($consumer_key, $consumer_secret,
$request_token, $request_token_secret);

// Ask Twitter for an access token (and an access token secret)
$request = $oauth->getAccessToken();

$access_token = $request['amp;oauth_token'];
$access_token_secret = $request['oauth_token_secret'];=======> HERE AM GETTING TROUBLE

function getAccessToken($token = NULL, $pin = NULL)
{
    if ($pin)
        $r = $this->oAuthRequest($this->accessTokenURL(),
            array("oauth_verifier" => $pin));
    else
        $r = $this->oAuthRequest($this->accessTokenURL());

    $token = $this->oAuthParseResponse($r);
    $this->token = new OAuthConsumer($token['oauth_token'],
        $token['oauth_token_secret']);

    return $token;
}

My complete Error Here

Notice: Undefined index: oauth_token_secret in E:\wamp\www\source\oauth\twitterOAuth\twitteroauth.php on line 118

Notice: Undefined index: oauth_token_secret in E:\wamp\www\source\oauth\bharani.php on line 18

8条回答
戒情不戒烟
2楼-- · 2019-04-02 18:09

I had the same error:

Notice: Undefined index: oauth_token in /web/htdocs/www.xxx.com/home/private/libraries> /twitteroauth/twitteroauth.php on line 118

Notice: Undefined index: oauth_token_secret in /web/htdocs/www.xxx.com/home/private/libraries/twitteroauth/twitteroauth.php on line 118

Debugging on line what the error specified:

function getAccessToken($oauth_verifier = FALSE) {
     // .... code .... //

     $token = OAuthUtil::parse_parameters($request);
     $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
     exit(print_r($token));

     // ... code ....//
}

I found this:

Array ( [ "1.0" encoding="UTF-8"?> Required oauth_verifier parameter not provided /oauth/access_token .......

After i read some issue on the web and find the solution. In my code i must pass a oauth_verifier:

 $request = $oauth->getAccessToken($_GET['oauth_verifier']);

Hope i help someone, the problem was that For OAuth 1.0a compliance 'oauth_verifier' is required!

Resource: https://dev.twitter.com/discussions/16443#comment-36618

Apologize for bad English.

查看更多
该账号已被封号
3楼-- · 2019-04-02 18:20

@Bharanikumar
AFAIK first you should call the function

$request_token = $oauth->getRequestToken();  

then u will get

$request_token['oauth_token']; and $request_token['oauth_token_secret']; 

then do below

 $URL = $oauth->getAuthorizeURL($request_token);

 $oauth = new TwitterOAuth('YOUR_CONSUMER_KEY', 'YOUR_CONSUMER_SECRET',  $request_token['oauth_token'],$request_token['oauth_token_secret']);  

 $access = $oauth->getAccessToken(NULL, $_GET['pin']);
 $accessToken = $access ['oauth_token'];
 $accessTokenSecret = $access ['oauth_token_secret'];

& then apply your code

if ($pin)

Hope this will help you..

查看更多
女痞
4楼-- · 2019-04-02 18:21

The problem is that there is an error in the request so you don't get oauth_token_secret in the respond from Twitter. Check out a simple but elaborate solution here.. http://errorbank.blogspot.com/2012/07/php-twitter-undefined-index.html

查看更多
别忘想泡老子
5楼-- · 2019-04-02 18:22

Please check php companents:

  • Curl SSL
  • Open SSL
  • hash_hmac
查看更多
时光不老,我们不散
6楼-- · 2019-04-02 18:23

This issue was solved for me by setting a Callback URL in my twitter application settings. http://dev.twitter.com

查看更多
祖国的老花朵
7楼-- · 2019-04-02 18:27

In your twitter application setting "Callback URL", add any callback url, for ex:
https://dev.twitter.com/

Otherwise twitter will consider your application as desktop application and you will get error:

Desktop applications only support the oauth_callback value 'oob'

and your php script will give errors like:

Notice: Undefined index: oauth_token in twitteroauth.php on line 80

But by setting a callback url from php script it will overwrite the default placeholder of callback url and consider your application as a web based application.

查看更多
登录 后发表回答