您好我试图使用oauth(PHP)发布推文
我在我的Twitter帐户中创建了应用程序,
我执行了一些开源脚本,但产生了以下错误,
Notice: Undefined index: oauth_token_secret in
如何解决这个问题
我的片段
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;
}
我完全错误在这里
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
在您的Twitter应用程序设置“回调URL”中,添加任何回调网址,例如: https://dev.twitter.com/
否则twitter会将您的应用程序视为桌面应用程序,您将收到错误:
Desktop applications only support the oauth_callback value 'oob'
你的PHP脚本将给出如下错误:
Notice: Undefined index: oauth_token in twitteroauth.php on line 80
但是通过从php脚本设置回调网址,它将覆盖回调网址的默认占位符,并将您的应用程序视为基于Web的应用程序。
我有同样的错误:
注意:未定义的索引:第118行的/web/htdocs/www.xxx.com/home/private/libraries> /twitteroauth/twitteroauth.php中的oauth_token
注意:未定义的索引:第118行的/web/htdocs/www.xxx.com/home/private/libraries/twitteroauth/twitteroauth.php中的oauth_token_secret
在线调试指定的错误:
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 ....//
}
我找到了这个:
数组([“1.0”编码=“UTF-8”?>未提供oauth_verifier参数/ oauth / access_token .......
我在网上阅读了一些问题并找到了解决方案。在我的代码中,我必须传递一个oauth_verifier:
$request = $oauth->getAccessToken($_GET['oauth_verifier']);
希望我帮助某人,问题是对于OAuth 1.0a,要求遵守“oauth_verifier”!
资源:https://dev.twitter.com/discussions/16443#comment-36618
为糟糕的英语道歉。
请检查php组件:
@Bharanikumar AFAIK首先应该调用该函数
$request_token = $oauth->getRequestToken();
然后你会得到
$request_token['oauth_token']; and $request_token['oauth_token_secret'];
然后在下面做
$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'];
然后应用您的代码
if ($pin)
希望对你有帮助..
问题是请求中存在错误,因此您不会在Twitter的响应中获得oauth_token_secret。在这里查看一个简单但精心设计的解决方案.. http://errorbank.blogspot.com/2012/07/php-twitter-undefined-index.html
通过在我的Twitter应用程序设置中设置回调URL,我解决了这个问题。 http://dev.twitter.com
我也是这个错误。因为我没有配置OAUTH_CALLBACK。希望对你有所帮助。
它只是一个通知。
您没有定义该数组索引或其他东西。粘贴你的完整错误和php写这个通知的地方。
另一种方法:您可以使用此代码禁用:
// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);