How can I use cURL (or any command line tool) to d

2019-04-19 17:36发布

I wish to use a command-line application, like cURL, to do some test posts to my test twitter account. I also wish to do this with OAuth authentication.

How I can do this? Assume I already have created an application, in Twitter, and received my keys and stuff.

(Also, please make sure you specify which key to use, and where, in the command line, etc.).

Finally, I'm under the (uneducated) assumption that this is possible with a single command line.

5条回答
我只想做你的唯一
2楼-- · 2019-04-19 17:58

Well, you're not the only one that's wished they could try out an OAuth-protected API with a simple curl command. You might look at oauth-proxy which sets up an HTTP proxy on your own machine with the appropriate parameters for tokens and secrets. Then any request which uses that proxy (like a curl command, for example, or even a web browser that's configured to use it) will automatically be signed with all the appropriate OAuth parameters.

Seth's walkthrough even includes the example of Twitter, so you should be able to follow the instructions step-by-step (assuming Twitter's OAuth works the same way it did in September 09).

This isn't quite as simple as a single line, since it involves installing some software and at least one additional command for setting up the proxy. But it should at least enable the goal of allowing easy, single-line tests with curl once things are set up.

查看更多
趁早两清
3楼-- · 2019-04-19 17:58

I don't think you can do it in one shot. OAuth requires that you respond with the token when you make the status request, which would be outside the scope of a single one-line curl request.

What you could do instead is use a simple library like the Twitter Ruby gem, which would be able to accept parameters at the command line and then produce the appropriate results.

查看更多
爷的心禁止访问
4楼-- · 2019-04-19 17:59

You can see a list of Twitter API libraries in different languages here. At least one of them works with Curl.

查看更多
干净又极端
5楼-- · 2019-04-19 18:03

Twitter actually came out with a modified version of cURL call Twurl. It is a ruby GEM that should do what you need.

查看更多
Lonely孤独者°
6楼-- · 2019-04-19 18:05

One thing to keep in mind is that you don't actually need to use OAuth. While it's true that Twitter discontinued basic authentication access in September 2010, there is still a way to use basic auth with cURL.

The idea is to send a user agent header which tricks Twitter into thinking that cURL is a regular browser. Luka Pušić wrote this script which shows you how.

查看更多
登录 后发表回答