6

How I can connect my extension to the API? I tried to use this example code for connecting:

SE.init({ clientId: 1, key: '?', channelUrl: '?', complete: function (data) { alert('connected') } }); SE.authenticate({ success: function(data) { alert('ok') }, error: function(data) { alert('error') }, networkUsers: true }); 

Which value I should put in channelUrl? And how I can register app and get token key, if it will work locally?

2
  • 1
    I'm having the same issue, did you manage to resolve this? Commented Sep 1, 2014 at 14:09
  • 1
    If anyone still has this issue, comment @ reply to me here and I will write up an answer. (But current low view count suggests very little interest.) And anonymous feedback is not promising either. Commented Aug 23, 2018 at 21:45

1 Answer 1

3

I've built an extension that uses StackExchange API using OAuth2 flow. I did not use the JS SDK and did it manually instead.

Here is how I did it:

function auth(sendResponse) { const scope = 'read_inbox,no_expiry,private_info'; const clientId = '12364'; const redirectUrl = chrome.identity.getRedirectURL('oauth2'); const url = `https://stackoverflow.com/oauth/dialog?client_id=${clientId}&scope=${scope}&redirect_uri=${redirectUrl}`; chrome.identity.launchWebAuthFlow( { url: url, interactive: true }, redirect_url => { const token = redirect_url.match(/access_token=(.+)/)[1]; sendResponse({ token }); } ); } 
2
  • 1
    This code works perfectly. But make sure to add the redirectUrl for your app as chromiumapp.org in the OAuth Domain in your stackApp configuration - reference (stackoverflow.com/a/31169304/6908282) Commented Sep 7, 2022 at 15:15
  • can you confirm if the OAuth Domain needs to be stackexchange.com instead. Because firefox has a different domain allizom.org, due to which i'm not able to use the plugin in firefox. Commented Sep 18, 2022 at 11:53

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.