1
我正在关注教程。我在授权用户方面遇到了一些麻烦。如何从Google Chrome扩展程序发送推文?
我正在向twitter发送用户授权。由于这是Chrome扩展,并且没有回调。我不知道如何代表该用户发送推文。 我是如何做的事情:
- 我有一个背景页面,其中包含授权用户来自twitter的代码。在用户安装扩展程序的时候,后台页面会将该用户发送给twitter以进行授权。我的授权方法正在通过回拨进行呼叫。但不知道我是否有一切可以发布推文。
- 现在当用户点击扩展图标时,popup.html将会出现。在此页面上,我希望用户发送推文。怎么样?
以下是我的代码:
manifest.json的
{
"name": "TweetChrome",
"version": "1.0",
"description": "Tweet from Chrome",
"browser_action": {
"default_icon": "images/share.png",
"popup": "popup.html"
},
"permissions": [
"tabs",
"http://ajax.googleapis.com",
"*://*.twitter.com/*",
"clipboardWrite"
],
"options_page": "options.html",
"background_page": "background.html"
}
background.html 我得到的回调方法的RESP一些HTML页面的标记。我不知道它是为了什么?
var oauth = ChromeExOAuth.initBackgroundPage({
'request_url': 'https://api.twitter.com/oauth/request_token',
'authorize_url': 'https://api.twitter.com/oauth/authorize',
'access_url': 'https://api.twitter.com/oauth/access_token',
'consumer_key': 'key',
'consumer_secret': 'secret',
'scope': '',
'app_name': 'TweetChrome'
});
oauth.authorize(onAuthorized);
function onAuthorized() {
var url = 'https://api.twitter.com/oauth/authorize';
/*as they are optional, i left empty*/
var request = {
'force_login': '',
'screen_name': ''
};
oauth.sendSignedRequest(url, callback, request);
};
function callback(resp, xhr) { alert('it get called too'); };
popup.html 鸣叫我使用的是借来的twitter.js。我没有写它。
Twitter.verify_credentials({install: true});
Twitter.update("test");
我的oauth方法是正确的在一个后台页面中?随着我的授权越来越多,我要为用户发布推文多远?
任何帮助将不胜感激。我希望解决这个问题,以完成我的扩展。
当用户第一次来。他必须得到授权。在用户授权后,我想我应该使用verify_credentials。然后我可以更新状态。我的这种理解是对的吗?其次,我的回调方法有混乱。我不知道我得到了什么。它将访问需要保存的令牌,但我不知道如何获取它们。它的任何指针? – 2012-03-16 11:43:54
图书馆为你做这一切。您可以使用'sendSignedRequest'开始发出请求,并且库将处理签名等。 – 2012-03-26 19:11:12