Skip to content

Instantly share code, notes, and snippets.

@geraintwhite
Forked from olls/twitter_api_proxy.js
Created April 7, 2014 00:23
Show Gist options
  • Select an option

  • Save geraintwhite/10013021 to your computer and use it in GitHub Desktop.

Select an option

Save geraintwhite/10013021 to your computer and use it in GitHub Desktop.
A Node.js app that allows the use of the Twitter API by client-side JavaScript.
/*
A simple Node.js proxy for Twitter's OAuth API.
*/
var http = require('http');
var url = require('url');
var t = require('twitter-js-client');
var twitter = new t.Twitter({
"consumerKey": "###",
"consumerSecret": "###",
"accessToken": "###",
"accessTokenSecret": "###",
"callBackUrl": "http://dvbris.com"
});
http.createServer(function (req, res) {
var url_parts = url.parse(req.url, true);
res.writeHead(200, {'Content-Type': 'application/json'});
function error(err) {
res.end(JSON.stringify(err));
}
function success(data) {
res.end(data);
}
twitter.doRequest(decodeURIComponent(url_parts.query.api_url), error, success);
}).listen(6001);
console.log('Server running at localhost:6001');
@geraintwhite
Copy link
Copy Markdown
Author

Allows Twitter API requests from client side JavaScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment