-
Notifications
You must be signed in to change notification settings - Fork 14
oAuth usage example
Marcos Reyes edited this page Jun 6, 2013
·
1 revision
This in an example of a request to Twitter API with with OAuth authentication:
var util = require('util');
var http = require('http');
var oauth = require('oauth-client');
var consumer = oauth.createConsumer('[your consumer key]', '[your consumer secret]');
var token = oauth.createToken('[token key]', '[token secret]');
var signer = oauth.createHmac(consumer, token);
var options = {
"port":3001,
"host":"localhost",
"path":"/",
"method":"GET",
"headers":{
"X-relayer-persistence":"BODY",
"X-Relayer-Host":"https://api.twitter.com:443/1.1/statuses/mentions_timeline.json"
}
};
// fillURL = function(path, host, port, https)
var uri = oauth.fillURL("/1.1/statuses/mentions_timeline.json", "api.twitter.com", 443, true);
options.headers.autorization = oauth.signRequest(options.method, uri, options.headers, options.body, signer).authorization;
var req = http.request(options, function (res) {
res.on('data', function (chunk) {
console.log(chunk.toString());
});
});
req.end();
1 - OVERVIEW
2 - API REFERENCE
2.1 - General Notes
2.1.1 - URI Structure
2.1.2 - HTTP Methods
2.1.3 - Security
2.1.4 - Errors
2.1.5 - Encoding
2.2 - REST Resources
2.3 - Data Models
3 - GETTING STARTED
4 - CONTRIBUTE
4.1 - Development Environment Setup
4.2 - How to Run the Tests (unit and acceptance)
4.3 - Tip & Tricks
5 - ANNEX
5.1 - Architecture