I'm making a chrome extension, which needs to get the current user's followers. The tumblr API says that I need to implement oauth and send requests as listed here. I implemented oauth following the example and using the library from google here.
So, the result was that the oauth.authorize
function would run, but the callback function, onFollowers
, wouldn't be called, leaving me to believe that I'm not getting a response from tumblr for some reason.
This is the code I ended up with:
background.html:
<html>
<script type="text/javascript" src="chrome_ex_oauthsimple.js"></script>
<script type="text/javascript" src="chrome_ex_oauth.js"></script>
<script type="text/javascript" src="background.js"></script>
</html>
background.js:
var oauth = ChromeExOAuth.initBackgroundPage({
'request_url' : 'POST http://www.tumblr.com/oauth/request_token',
'authorize_url' : 'http://www.tumblr.com/oauth/authorize',
'access_url' : 'POST http://www.tumblr.com/oauth/access_token',
'consumer_key' : '[key provided]',
'consumer_secret' : '[secret provided]',
'app_name' : '[app name]'
});
var followers = null;
var baseHostname = localStorage.getItem('BaseHostname');
function onFollowers(text, xhr) {
//parsing JSON response
}
function getFollowers() {
oauth.authorize(function() {
var url = "api.tumblr.com/v2/blog/"+baseHostname+"/followers";
oauth.sendSignedRequest(url, onFollowers, {
'parameters' : {
'base-hostname' : baseHostname
}
});
});
};
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.greeting == "getFollowers")
console.log(baseHostname);
getFollowers();
sendResponse({farewell: "getFollowers function run success"});
});
Am I missing something?