4

I am writing a simple bash script to download stream from Twitter:

curl -H "Authorization: ${TOKEN}" "$URL"

and I am looking for a way to generate the $TOKEN. I have all the input necessary (CONSUMER_KEY, ...), but where can I get the program oauth_sign that will generate the token from the input data?

TOKEN=$(oauth_sign $CONSUMER_KEY $CONSUMER_SECRET $ACCESS_TOKEN $ACCESS_SECRET GET $URL)
Martin Vegter
  • 69
  • 66
  • 195
  • 326
  • http://acme.com/software/oauth_sign/ – goldilocks Sep 15 '13 at 13:23
  • If you want a more elaborate example there is this: http://www.bentasker.co.uk/documentation/20-developmentprogramming/23-howto-tweet-from-bash-scripts-using-oauth – slm Sep 15 '13 at 13:25

2 Answers2

5

I just downloaded the link @goldilocks provided, http://acme.com/software/oauth_sign/, and confirmed that it compiles. Looks very straightfoward.

compile

$ make
gcc -c -Wall -O liboauthsign.c
liboauthsign.c: In function ‘oauth_sign’:
liboauthsign.c:123:5: warning: implicit declaration of function ‘getpid’
liboauthsign.c:305:5: warning: pointer targets in passing argument 4 of ‘HMAC’ differ in signedness
/usr/include/openssl/hmac.h:99:16: note: expected ‘const unsigned char *’ but argument is of type ‘char *’
rm -f liboauthsign.a
ar rc liboauthsign.a liboauthsign.o
ranlib liboauthsign.a
gcc -Wall -O oauth_sign.c -L. -loauthsign -lcrypto -o oauth_sign

usage

$ ./oauth_sign --help
usage:  oauth_sign [-q] consumer_key consumer_key_secret token token_secret method url [name=value ...]

excerpt from README

To use it, you supply the four cryptographic cookies and the method and URL of the request. If it's a POST request with extra parameters, you have to give those too. Oauth_sign puts all this together and makes the signature string. The signature is generated using HMAC-SHA1 as specified in RFC section 3.4.2, and is returned as an Authorization header value as specified in RFC section 3.5.1. This header can then be used in an HTTP request via, for example, the -h flag in http_get(1) and http_post(1) or the -H flag in curl(1).

Looks like it comes with a library exposing the fuctions for use in your own C applications as well.

slm
  • 363,520
  • 117
  • 767
  • 871
1

Get a stream feed from a Twitter user uses bash commands to open a stream from Twitter. (from commandlinefu.com)

commandlinefu.com capture

Step1 - Create the four oauth keys required for a Twitter stream feed.

Step2 - Create the signature base string required for a Twitter stream feed.

Step3 - Create the oauth token required for a Twitter stream feed.

Step4 - Create the authorization header required for a Twitter stream feed.

neonzeon
  • 400
  • 2
  • 9