【发布时间】:2014-04-15 21:21:05
【问题描述】:
我正在测试 phone gap oauthio 插件,但无法让它工作
遵循文档。
使用命令行添加插件 并且还安装了inappbrowser
还将它添加到我的 config.xml 中
<gap:plugin name="org.apache.cordova.inappbrowser" />
<gap:plugin name="com.phonegap.plugins.oauthio" />
inappbrowser 已加载并正在工作。 但 OAUTH 不是。 我在这里和那里添加了一些警报() 但是当我添加警报以显示 OAUTH 内容时,它不会发生
alert('device ready'); //to see if the device is ready, no problems here
alert(window.open); //to see if inbrowserapp is loaded, no problems here
alert(OAuth);// no message. looks like is not defined,also tried alert(OAuth.initialize) same luck
OAuth.initialize("VeQmyEu0QtzIOO9WjM1IlAU0ty4");
alert('postinit');
在插件内部定义为“OAuth”,所以名称没问题,我安装的插件是
oauthio-test % phonegap plugin list
[phonegap] com.phonegap.plugins.oauthio
[phonegap] org.apache.cordova.inappbrowser
我还删除了“platform/ios”的内容以防止文件缓存
我的访问权限是这些
<access origin="*" />
<access origin="http://127.0.0.1*"/> <!-- allow local pages -->
<access origin="*graph.facebook.com*" />
<access origin="*api.twitter.com*" />
<access origin="*github.com*" />
到目前为止没有运气。 感觉就像我在 IE6 中调试的时候一样
编辑: 添加了完整的代码,显示我在事件“ondeviceready”中
$(document).on('deviceready', function() {
alert('device ready');//shows ok
alert(window.open); //shows ok
alert(OAuth.OAuth.initialize);//it dies here
OAuth.initialize("VeQmyEu0QtzIOO9WjM1IlAU0ty4");
alert('postinit');//this alert won't displayed
$('#fb-connect').on('click', function() {
$('#result').html("");
OAuth.popup("facebook", function(e,r) {
if (e)
$('#result').html('error: ' + e.message);
else
// the access_token is available via r.access_token
// but the http functions automagically wrap the jquery calls
r.get('/me').done(function(data) {
$('#result').html("facebook: Hello, " + data.name + " !");
});
});
});
【问题讨论】:
-
你有没有试过只使用
<access origin="*" />如果你有其他的就不需要了,而且我不是 100% 它们是可堆叠的(意味着最后一个可能是唯一被使用的) -
我刚刚在上次尝试中添加了它,也尝试了你所说的。还是一样的结果。就像没有被加载,我不知道如何调试这个:(
-
您确定只在
deviceready事件触发后调用插件吗?如果没有,我可以举个例子 -
是的。我添加了更多代码。可悲的是,我使用了插件网站上的示例,即使这样也不起作用
-
这条线不正确
alert(OAuth.OAuth.initialize);//it dies here我想你的意思是alert(OAuth);。这只是上面或实际来源中的错字吗?