Zend OAuth 与 twitter 单一访问令牌 [英] Zend OAuth with twitter single access tokens

查看:18
本文介绍了Zend OAuth 与 twitter 单一访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,它要求用户使用 Twitter 和 OAuth 登录.感谢 Zend_OAuth,一切正常.问题是 Web 应用程序也会对 twitter API 进行一些调用,但这些调用将在内部处理而无需进行身份验证.为此,Twitter Dev 提供了access_token"和access_token_secret"密钥(此处提到 http://dev.twitter.com/pages/oauth_single_token )

I'm developing an application where it requires users to sign in using twitter and OAuth. Everything works just fine thanks to Zend_OAuth. The problem is that the web app will also make some calls to the twitter API but these will be handled internally without the need of authenticating. Twitter Dev provides an 'access_token' and 'access_token_secret' keys for this purpose (Mentioned here http://dev.twitter.com/pages/oauth_single_token )

问题是我无法让 Zend_OAuth 与现有的访问令牌配合使用.有没有人可以提供几行代码帮助我如何使用现有密钥进行 API 调用而不会被重定向到 Twitter 的授权页面?我知道这是可以做到的.

The problem is that I can't get Zend_OAuth to play nice with existing access tokens. Is there anyone who can help with a few lines of code how can I make an API call with my existing keys without being redirected to Twitter's Authorize page ? I know it can be done.

附注.如果可能的话,我不想使用像 dev.twitter.com 中提到的那样的外部库——正是 Zend Framework 所提供的

PS. If possible, I don't want to use external libraries like the ones mentioned in dev.twitter.com - just what Zend Framework is offering

谢谢!

推荐答案

使用 ZF 1.10.8 版在 Twitter 上发布所需的最少代码是:

With ZF version 1.10.8 minimal code required to post on Twitter is:

$token = new Zend_Oauth_Token_Access;
$token->setParams(array(
'oauth_token' => 'REPLACE_WITH_TOKEN',
'oauth_token_secret' => 'REPLACE_WITH_TOKEN_SECRET'
));

$twitter = new Zend_Service_Twitter(array(
'consumerKey' => 'REPLACE_WITH_CONSUMER_KEY', 
'consumerSecret' => 'REPLACE_WITH_CONSUMER_SECRET',
'accessToken' => $token
));

$response = $twitter->status->update('REPLACE WITH MESSAGE');

http://dev.twitter.com上注册您的应用程序后,即可访问所有令牌和机密信息

All tokens and secrets can be accessed after registering your application on http://dev.twitter.com

这篇关于Zend OAuth 与 twitter 单一访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆