新 Twitter API 1.1 的身份验证 [英] Authentication for new Twitter API 1.1

查看:47
本文介绍了新 Twitter API 1.1 的身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序需要在公共页面上为随机用户显示关注者和关注者的数量(users/show.json)(不需要身份验证).使用 Twitter API 1.0 非常容易,因为请求不需要身份验证.使用新的 Twitter API 1.1 不再可能,因此我需要对请求进行身份验证(通过 OAuth).

I have an application that needs to display number of followers and following (users/show.json) for a random user on a public page (authentication is not required). With the Twitter API 1.0 it was quite easy as authentication is not needed for the request. With the new Twitter API 1.1 is no more possible, so I need to authenticate the request (via OAuth).

是否只能验证"应用程序而不是用户?我的意思是:我可以避免要求用户登录并且只使用应用程序密钥/秘密进行身份验证吗?或者每次我也需要使用用户凭据创建令牌,创建回调等?

Is it possible only "authenticate" the application and not the user too? I mean: can I avoid to ask user to login and only authenticate with application key/secret? Or everytime I need to create a token with user credentials too, creating callback, etc.?

推荐答案

是的,这是可能的!如果您的应用程序不需要执行诸如发布状态或代表用户发送直接消息之类的操作,您应该能够使用一组硬编码的 Twitter OAuth 凭据,不需要用户进行身份验证.

Yes, it is possible! If your application doesn't need to do things like post statuses or send direct messages on behalf of a user, you should be able to retrieve all of a user's public information with a single hardcoded set of Twitter OAuth credentials, and not require the user to authenticate.

  • 登录 Twitter 并转到位于 https://dev.twitter.com/apps
  • 注册一个新的应用程序;申请注册后,查看申请详情.您会看到一个OAuth 工具"选项卡,您可以在其中找到该应用程序的所有相关 OAuth 值:消费者密钥、消费者秘密、访问令牌和访问令牌秘密.
  • 使用这些凭据,您将能够向新的 Twitter API 发出请求.

如果您不习惯直接使用 Twitter API,那么有许多适用于各种语言的优秀 API 包装器——其中包括 Temboo SDK,它会为您提供调用各种方法的代码片段(以及为您提供了一个安全地存储您的 Twitter 凭据的地方,因此您无需将它们添加到您的应用程序中).

If you're not comfortable using the Twitter API directly, there are a number of good API wrappers out there for various languages -- among others, the Temboo SDK, which will give you code snippets for calling various methods (and also gives you a place to securely store your Twitter credentials, so you don't need to bake them into your application).

看看:

(完全披露:我在 Temboo 工作.)

(Full disclosure: I work at Temboo.)

这篇关于新 Twitter API 1.1 的身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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