gpt4 book ai didi

php - Zend_Service_Twitter - 在尝试任何 API 之前使用其 OAuth 功能获取访问 token

转载 作者:行者123 更新时间:2023-12-02 22:30:44 26 4
gpt4 key购买 nike

我正在尝试使用 Zend 开发一个模块,它将查找我最新的推文并显示在我的博客上。

我已经阅读并学习了关于 Zend_Service_Twitter 的知识,并且通过这门课,我想我应该从我的 Twitter 上获取最新的推文。

当我启动下面给出的代码时:

public function indexAction() {

$token = unserialize('XXXXX');
$twitter = new Zend_Service_Twitter(array(
'username' => 'XXX',
'accessToken' => $token,
'consumerKey' => 'XXXX',
'consumerSecret' => 'XXXX',
'callbackUrl' => 'http://localhost/zendtest/public/blog'
));

// verify user's credentials with Twitter
$response = $twitter->account->verifyCredentials();

// Get Timeline
$response = $twitter->status->userTimeline();

$this->view->twitresponse = $response;

}

我收到这个错误:

Fatal error:
Uncaught exception 'Zend_Service_Twitter_Exception' with message 'Twitter session is unauthorised. You need to initialize Zend_Service_Twitter with an OAuth Access Token or use its OAuth functionality to obtain an Access Token before attempting any API actions that require authorisation' in D:\Server\xampp\htdocs\zendtest\library\Zend\Service\Twitter.php:282

Stack trace:
#0 D:\Server\xampp\htdocs\zendtest\library\Zend\Service\Twitter.php(769): Zend_Service_Twitter->_init()
#1 [internal function]: Zend_Service_Twitter->accountVerifyCredentials()
#2 D:\Server\xampp\htdocs\zendtest\library\Zend\Service\Twitter.php(270): call_user_func_array(Array, Array)
#3 [internal function]: Zend_Service_Twitter->__call('verifyCredentia...', Array)
#4 D:\Server\xampp\htdocs\zendtest\application\modules\twitter\controllers\TwitterServiceController.php(27): Zend_Service_Twitter->verifyCredentials()
#5 D:\Server\xampp\htdocs\zendtest\library\Zend\Controller\Action.php(516): Twitter_TwitterServiceController->indexAction()
#6 D:\S in D:\Server\xampp\htdocs\zendtest\library\Zend\Controller\Plugin\Broker.php on line 336

我在 Internet 和此处上有很多文章,但仍然无法解决我的问题。

有谁知道如何处理这个问题?
Zend_Oauth_Consumer 的共同点是什么?

最佳答案

如果您只想显示您的自己的 时间轴,您可以在 Twitter 开发者页面上“直接”请求 token ,并将其“硬编码”到您的应用程序中。所以你不必处理重定向和授权过程。试试这个:(未经测试,因为我正在运行..)

    $token = new Zend_Oauth_Token_Access();

$token->setParams(array(
'oauth_token' => 'oAUTH-TOKEN',
'oauth_token_secret' => 'oAUTH-TOKEN-SECRET',
));

$twitter = new Zend_Service_Twitter(array(
'username' => 'USER',
'consumerKey' => 'CONSUMER-KEY',
'consumerSecret' => 'CONSUMER-SECRET',
'accessToken' => $token
));


$timeLine = $twitter->status->userTimeline();

关于php - Zend_Service_Twitter - 在尝试任何 API 之前使用其 OAuth 功能获取访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12309661/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com