OAuth.io连接失败 [英] OAuth.io connection failed
问题描述
我是网络编程的新手,我尝试在我的网络应用中使用oauth.io。根据指示,我完成了对Facebook和Google的配置。一切正常,当我从他们的网站测试配置。但是,当我试图执行到我的web应用程序时,OAuth将不会连接到提供程序。
我在html中加载了oauth.js,在html中创建了一个按钮,并使用 onclick =pop
在javascript中调用函数。在JavaScript中的 pop()
函数中,我添加了:
OAuth.initialize('the-public-key-in-my-acc);
OAuth.popup('facebook',function(err,res){if(err){alert(something)}) ;
然后点击按钮,一个弹出窗口立即闪出并立即关闭。尝试使用OAuth.redirect并将其重定向到 http://oauth-io.github.io/oauth -js 或我的本地主机,但它说连接失败。
执行过程中是否存在缺失/错误?
非常感谢您的帮助。
PS:我正在使用本地主机,并试图将redirect-url设置为localhost:但是仍然失败:(b / b)
以下是我写的示例代码:
Html:
< div>< button onclick =oauthPop()>尝试OAuth-io< / button>< / DIV>
JS:
var oauthPop = function(){
OAuth.initialize('my-pub-key-on-authio');
OAuth.popup('facebook',function(err,res){//或OAuth.callback
//处理err错误
if(err){
alert( error)
} else {
//从fb获取我的名字
res.get('/ me')。done(function(data){
alert(data .name)
})
}});
}
OAuth.io需要使用 OAuth.popup()
的结果加载jQuery以发出HTTP请求。它在场景后面使用 jQuery.ajax(),让所有人都知道它的功能您可能需要的选项。
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)
})
}});
}
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.
这篇关于OAuth.io连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!