Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use cURL (or any command line tool) to do an HTTP Post to Twitter, with OAuth authentication?

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.

like image 743
Pure.Krome Avatar asked Mar 02 '10 01:03

Pure.Krome


People also ask

How do I get my Twitter OAuth token?

Login to your Twitter account on developer.twitter.com. Navigate to the Twitter app dashboard and open the Twitter app for which you would like to generate access tokens. Navigate to the "Keys and Tokens" page. Select 'Create' under the "Access token & access token secret" section.

Can I use Twitter API without authentication?

You can do application-only authentication using your apps consumer API keys, or by using a App only Access Token (Bearer Token). This means that the only requests you can make to a Twitter API must not require an authenticated user.


2 Answers

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.

like image 180
npdoty Avatar answered Oct 29 '22 17:10

npdoty


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

like image 25
jonathanberi Avatar answered Oct 29 '22 17:10

jonathanberi