3

I'm new to web programming and I try to use oauth.io in my web-app. I finished configurations to facebook and Google due to the instruction. Everything works fine when i tested the configuration from their site. However when i tried to implemented to my webapp, OAuth won't connect to the provider.

I loaded the oauth.js in html, created a button in html and use onclick="pop" to invoke the function in javascript. And within the pop() function in javascript I've added:

OAuth.initialize('the-public-key-in-my-acc");
OAuth.popup('facebook', function(err, res) { if (err) { alert(something)});

Then I click the button. a popup window just flashed up and closed immediately. I've also tried to use OAuth.redirect and redirect it to http://oauth-io.github.io/oauth-js or my localhost, but then it says connection failed.

Is there something missing/wrong in the implementation?

Thanks a lot for the help.

PS: I'm working on localhost and i've tried to set redirect-url to localhost:portnr. but still failed. :(

Here is the sample code i've written:

Html:

<div><button onclick="oauthPop()">Try OAuth-io</button></div>

JS:

var oauthPop = function() {
OAuth.initialize('my-pub-key-on-authio');
OAuth.popup('facebook', function(err, res) { // or OAuth.callback
    // handle error with err
    if (err) {
        alert ("error")
    } else {
        // get my name from fb
        res.get('/me').done(function(data) {
            alert(data.name)
        })
    }});
}
honk
  • 9,137
  • 11
  • 75
  • 83
ingram87
  • 31
  • 1

1 Answers1

2

OAuth.io needs to have jQuery loaded to make HTTP requests using the result of OAuth.popup(). It use jQuery.ajax() behind the scene to let you a well-known function with all the option you might need.

Thibaud Arnault
  • 1,435
  • 14
  • 21
  • I am also facing this issue but not get any solution till that "res" is undefined in OAuth.popup('facebook', function(err, res) {}) this is only happen in live server not on local please help – RaviPatidar Dec 10 '15 at 13:17
  • @RaviPatidar if `res` is empty, you should have something in `err` that describe why there is an error (console.log(err)). Have you add your live server to the whitelisted domain in OAuth.io? – Thibaud Arnault Dec 22 '15 at 22:43
  • yes I have added console.log(err) there is an error msg so that I used another way to get followers list using php Thanks for reply @Thibaud arnault – RaviPatidar Dec 23 '15 at 08:51