How to send tweet from Google Chrome Extension?


#1

I am following Google oAuth tutorial. And I am having some trouble with authorizing user.

I am sending user to twitter for authorization. As this is chrome extension and there is no callback. I dont know how to send tweet on the behalf of that user. How I am doing things:

1). I have a background page that has the code of authorizing user from twitter. On the time when user install the extension, background page send that user to twitter for authorization. My authorization method is getting called with their call back. But dont know if I am having everything to make a tweet.

2). Now when user will click on extension icon, the popup.html will be appear. And on this page I want user to send a tweet. How?

Following is my code:

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

I am getting some html page markup in resp of callback
method. I dont know what it is for?

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 

To tweet I am using a borrowed twitter.js <https://github.com/abraham/omnitweet/blob/master/extension/javascript/twitter.js>. 
I didn't wrote it. 

<code>Twitter.verify_credentials({install: true}); 
Twitter.update("test");

My approach of oauth is right on having it in a background page? As my
authorization is getting call how much far I am to make a tweet for a
user?
Any help will be appreciated. I am hopeful to solve this issue to
finish my extension.


#2

First, I must obligatorily recommend that you not perform OAuth via Javascript – even in a browser extension. It’s a poor conduit for this protocol.

Because you are in a web browser, a callback is actually the right choice for you. You’re in a browser that can receive URLs – you can declare a custom URI scheme for you to respond to and dynamically tell oauth/request_token this value via oauth_callback so that the user will be redirected after the oauth/authorize step. Also, providing parameters and leaving the value empty is not the same as not providing the parameters at all.


#3

a little late to the party, but, is there tutorial on how to make a chrome extension that connects to the twitter new api? obviously not using OAuth as you suggest. It seems there’s little documentation on how to do this on the client-side, it seems all the documentation is for server-side scripts.