-
Notifications
You must be signed in to change notification settings - Fork 11
OAuth How To
chrislongo edited this page Dec 24, 2011
·
8 revisions
OAuth is enabled per host via a configuration file in ~/.httpshell/
with the format <hostname>.json
OAuth is available in httpshell 0.8.0 and up.
Create a file named ~/.httpshell/api.twitter.com.json
. The contents should look like:
{
"consumer":
{
"consumer-key": "YOUR CONSUMER KEY",
"consumer-secret": "YOUR CONSUMER SECRET"
},
"access":
{
"access-token": "YOUR ACCESS TOKEN",
"access-token-secret": "YOUR ACCESS TOKEN SECRET"
}
}
Now access the API with httpshell:
api.twitter.com:/> get /1/statuses/mentions.json
Using OAuth config in /Users/chris/.httpshell/api.twitter.com.json
Connecting to https://api.twitter.com/1/statuses/mentions.json
HTTP/1.1 200 OK
...
If something goes wrong Twitter will respond with:
{"error":"Could not authenticate you.","request":"\/1\/statuses\/mentions.json"}
This is usually because one of your keys or secrets is incorrect. Verify them at the Twitter developer's site.
Most web APIs do not require an access token. Flickr is one example.
~/.httpshell/api.flickr.com.json
{
"consumer":
{
"consumer-key": "YOUR FLICKR KEY",
"consumer-secret": "YOUR FLICKR SECRET"
}
}
api.flickr.com:/> get /services/rest/?method=flickr.test.echo
Using OAuth config in /Users/chris/.httpshell/api.flickr.com.json
Connecting to http://api.flickr.com/services/rest/?method=flickr.test.echo
HTTP/1.1 200 OK
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<oauth_body_hash>...</oauth_body_hash>
<oauth_nonce>24451477</oauth_nonce>
<oauth_timestamp>1324693478</oauth_timestamp>
<oauth_consumer_key>...</oauth_consumer_key>
<oauth_signature_method>HMAC-SHA1</oauth_signature_method>
<oauth_version>1.0</oauth_version>
<oauth_signature>...</oauth_signature>
<method>flickr.test.echo</method>
<api_auth_is_oauth>1</api_auth_is_oauth>
<api_key>...</api_key>
<api_sig>...</api_sig>
<auth_token />
</rsp>