node.js - Login With Evernote -
im trying connect evernote meteor.
but im having bad time, trying oauth token, trying follow example evernote sample meteor, pretty old (2 years), try follow , idea.
i can connect evernote, login page , email verification, problem raised on meteor method.
handlecallback, wich need "verify" param, wich in case
ouath_token
second try.
on evernote npm readme suggest use oauthjs, , try code.
var hostname = "http://sandbox.evernote.com"; var options,oauth; options = { consumerkey: 'xxxxxxxxx', consumersecret: 'xxxxxxxxx', callbackurl : 'http://localhost:3000/oauth/auth', signaturemethod : "hmac-sha1", }; oauth.request({'method': 'get', 'url': hostname + '/oauth', 'success': function(data){ console.log(data); }, 'failure': function(data){ console.log(data); }});
but return
(stderr) no valid request transport found.
so im pretty stucked here.
the npm module provided evernote includes helper functions oauth working.
install evernote npm module via:
$npm install evernote
below simplest single file example of implementing oauth in evernote application put together. change values of consumer_key
, consumer_secret
below , should run fine if you've installed evernote:
var evernote = require('evernote').evernote; var http = require("http"); var url = require("url"); consumer_key="put consumer key here"; consumer_secret="put consumer secret here"; if (consumer_key === "put consumer key here"){ console.error("\nplease enter evernote consumer key , secret\n\nif don't have key can 1 at:\nhttps://dev.evernote.com/#apikey\n") process.exit(1) } var global = {}; global.oauthtoken = ''; global.oauthsecret = ''; function getoauthverifier(url) { var regex = new regexp("[\\?&]oauth_verifier=([^&#]*)"), results = regex.exec(url); return results === null ? "" : decodeuricomponent(results[1].replace(/\+/g, " ")); } var handler = function(request, response) { var params = url.parse(request.url) var pathname = params.pathname; console.log("request " + pathname + " received."); var client = new evernote.client ({ consumerkey: "put consumer key here", consumersecret: "put consumer secret here", sandbox: true }); if (pathname == "/"){ var callbackurl = 'http://localhost:8888/oauth'; client.getrequesttoken(callbackurl, function(err, oauthtoken, oauthsecret, results){ if(err) { console.log(err); } else { global.oauthtoken = oauthtoken; global.oauthsecret = oauthsecret; console.log("set oauth token , secret"); var authorizeurl = client.getauthorizeurl(oauthtoken); console.log(authorizeurl); response.writehead(200, {"content-type":"text/html"}); response.write("please <a href=\""+authorizeurl+"\">click here</a> authorize application"); response.end(); } }); } else if (pathname == "/oauth"){ client.getaccesstoken( global.oauthtoken, global.oauthsecret, getoauthverifier(params.search), function(error, oauthaccesstoken, oauthaccesstokensecret, results) { if(error) { console.log("error\n\n\n"); console.log(error); } else { response.writehead(200, {"content-type":"text/html"}); response.write(oauthaccesstoken); response.end(); } } ); } else { response.writehead(200, {"content-type":"text/html"}); response.write("not valid url <a href=\"/\"> go home </a>"); response.end(); } }; http.createserver(handler).listen(8888);
Comments
Post a Comment