如何使用curl访问Twitter REST API v1.1? [英] How to access Twitter REST API v1.1 using curl?

查看:172
本文介绍了如何使用curl访问Twitter REST API v1.1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用测试OAuth功能(应用程序设置),我可以为指定的API请求生成完全设置的curl命令:

Using the "Test OAuth" feature (application settings) I can generate a fully set up curl command for a specified API request:

curl --get 'https://api.twitter.com/1.1/followers/ids.json' 
  --data 'count=10&cursor=-1&screen_name=microsoft' 
  --header 'Authorization: OAuth 
      oauth_consumer_key="123consumer", 
      oauth_nonce="123nonce", 
      oauth_signature="123signature%3D", 
      oauth_signature_method="HMAC-SHA1", 
      oauth_timestamp="1402309080", 
      oauth_token="123-token", 
      oauth_version="1.0"' 
  --verbose 

这正是我想做的,但是API请求有所不同。但是,仅将上述命令中的 microsoft与 google进行交换会导致错误:

This is exactly what I would like to do but with varying API requests. But just exchanging "microsoft" in above command with "google" will cause an error:

{"errors":[{"message":"Could not authenticate you","code":32}]}

为什么

据我了解OAuth,我对请求进行授权所需要的只是下表的步骤G中列出的oauth-key /值:

As far as I understand OAuth all I need for authorizing a request is the oauth-key/values listed in step G of the following chart:

这是官方答案:授权请求

推荐答案

更改参数时, OAuth签名基本字符串确实会发生变化,因此 oauth_signature 标头也不会更改。这就是为什么更改参数时不能重用签名的原因。

When you change the parameters, the OAuth signature base string does change, so the oauth_signature header does also change. That's why you can't reuse the signature when you change the parameters.

如果您想查看针对Twitter API的任何特定请求的curl请求,请查看OS X的 STTwitter 库。该演示项目包括一个GUI客户端,该客户端将向您展示 curl格式的OAuth请求。

If you want to see the curl request for any specific request to Twitter API, have a look at the STTwitter library for OS X. The demo project includes a GUI client that will show you the OAuth request in curl format.

现在,如果您的目标只是从命令行向Twitter发送请求,请查看 twurl Twitter API的命令行客户端。

Now if your goal is just issuing requests to Twitter from command line, check out twurl which is a command-line client for Twitter API.

这篇关于如何使用curl访问Twitter REST API v1.1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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