Twitter API获取状态/ user_timeline - 如何包含身份验证? [英] Twitter API GET statuses/user_timeline - how to include authentication?

查看:199
本文介绍了Twitter API获取状态/ user_timeline - 如何包含身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如获取请求:

https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=twitterapi&count = 2



如此处所述:

https://dev.twitter.com/docs/api/1/get/statuses/user_timeline

我有一个oauth用户令牌和用户令牌密码,加上我的应用凭证...



身份验证是受支持的,但是如何将它包含在不能公开访问的屏幕名称的获取请求中? 如果我正确理解您的问题,您希望能够通过OAuth令牌和秘密获得来自第三方用户的推文属于您网站上的用户。来自第三方用户的推文不可公开访问,但您的用户有访问权限。这是正确的吗?



通常,如果您想代表用户访问私人资源,则必须用OAuth令牌和您的应用程序凭证签署请求。然后,Twitter可以检查,哪个用户在您的网站上登录过,以及用户是否授予了您的网站访问权。



该签名在GET请求的标题中发送一个这样的格式:

$ p $授权
OAuth oauth_consumer_key =xvz1evFS4wEEPTGEFPHBog,
oauth_nonce =kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg ,
oauth_signature =tnnArxj06cWHq44gCs1OSKk%2FjLY%3D,
oauth_signature_method =HMAC-SHA1,
oauth_timestamp =1318622958,
oauth_token =370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9we​​JAEb,
oauth_version =1.0

Twitter上还有关于如何计算签名。


For the example get request:

https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=twitterapi&count=2

As documented here:

https://dev.twitter.com/docs/api/1/get/statuses/user_timeline

I have an oauth user token and user token secret, plus my app credentials...

The docs state that authentication is supported, but how do I include it in the get request for screen names that are not publicly accessible?

解决方案

If I understand your question right, you want to be able to get the tweets from a third-party user with the OAuth token and secrets belonging to a user on your site. The tweets from the third-party user are not publicly accessible, but your user has access rights to them. Is this right?

Generally if you want to access private ressources on behalf of your user, you have to sign the request with the OAuth token and your application credentials. Then Twitter can check, which user is signed in on your site and if the user gave your site access rights.

That signature is sent within the header of your GET request in a format like this:

Authorization: 
        OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog", 
              oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg", 
              oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D", 
              oauth_signature_method="HMAC-SHA1", 
              oauth_timestamp="1318622958", 
              oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb", 
              oauth_version="1.0"

There is also documentation from Twitter on how to calculate the signature.

这篇关于Twitter API获取状态/ user_timeline - 如何包含身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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