How to authorize from Twitter API in Google Chrome Extension?

774 views
Skip to first unread message

Tahir Akram

unread,
Mar 1, 2012, 4:17:28 PM3/1/12
to Chromium-extensions
I am making a Chrome extension that will tweet.

Following is my code.

<script type="text/javascript" src="chrome_ex_oauthsimple.js"></
script>
<script type="text/javascript" src="chrome_ex_oauth.js"></script>
<script>
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': '--',
'consumer_secret': '--',
'scope': '',
'app_name': 'TweetOChrome'
});


jQuery(function() {
jQuery('#connect').click(function (){

oauth.authorize(install);
});
});

function install() {
console.log('installed successfully!');
}

</script>

Seems I am middle of some where. I can see a redirect page showing
"Redirecting..." but it does not do any thing.

Any help here?

Tahir Akram

unread,
Mar 3, 2012, 10:51:51 AM3/3/12
to Chromium-extensions
I have modified my code a bit. I have this code in my popup.html. And
getting following error:

Cannot read property 'chromeExOAuthConfig' of null
Screensot: http://i.stack.imgur.com/T29w0.png

<script type="text/javascript" src="chrome_ex_oauthsimple.js"></
script>
<script type="text/javascript" src="chrome_ex_oauth.js"></script>

jQuery(function() {

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': '---',
'consumer_secret': '---',
'scope': '',
'app_name': 'Tweet'
});
jQuery('#connect').click(function (){

oauth.authorize(install);
});
});

function install() {
alert('success')
}

function callback(resp, xhr) {
// ... Process text response ...
};

Following is my manifest.json file

{
"name": "Tweet",
"version": "1.0",
"description": "Tweet.",
"browser_action": {
"default_icon": "icon.png",
"popup": "popup.html"
},
"permissions": [
"tabs",
"http://ajax.googleapis.com",
"*://*.twitter.com/*",
"clipboardWrite"
]

Tahir Akram

unread,
Mar 5, 2012, 9:53:55 AM3/5/12
to Chromium-extensions
Any help on this issue?

Andy Jiang

unread,
Jun 18, 2017, 8:13:20 PM6/18/17
to Chromium-Extensions-Announce
Hey Tahir,

I know this is super late, but in case somebody else comes across this thread, hopefully this will be able to help them.

Authing into twitter in the chrome extension requires:
- setting a URL for the callback URL in the twitter apps settings page
- injecting a content script on that same URL in your chrome extension; where the script will parse the tokens from the query strings and then send that as a message to your background script
- in your background script, then you use those tokens to perform the third and final leg of the oauth process


Hope that helps!
Reply all
Reply to author
Forward
0 new messages