2012-09-09 50 views
2

我在做一个Chrome扩展,它需要获取当前用户的追随者。 tumblr API表示我需要实施oauth并发送请求,列出here。我按照示例使用了oauth,并使用了谷歌的here库。从Tumblr的API调用没有回调

因此,结果是oauth.authorize函数会运行,但回调函数onFollowers不会被调用,让我相信我没有从tumblr得到一个响应,因为某些原因。

这是我结束了代码:

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"}); 
    }); 

我缺少的东西?

回答