谷歌登录Phonegap

时间:2014-08-08 14:14:46

标签: javascript oauth-2.0 sencha-touch google-login hello.js

身份验证页面未返回重定向网址并显示404错误。我需要移动中的运行项目。我正在使用phonegap构建,但移动设备没有localhost。如何将本地文件定义为redirect_uri?

之后返回此网址
  

http:// localhost /cevap/redirect.html?state=%7B%22client_id%22:%2275055614045-a999nkehht0jk3i46548qg32imu0toqg.apps.googleusercontent.com%22,%22network%22:%22google%22,%22display% 22:%22popup%22%22callback%22:%22_hellojs_8ws7jbej%22%22state%22:%22%22%22oauth_proxy%22:%22https://auth-server.herokuapp.com/proxy%22,% 22scope%22:%22friends,基本%22%22oauth%22:%7B%22version%22:2,%22auth%22:%22https://accounts.google.com/o/oauth2/auth%22,% 22grant%22:%22https://accounts.google.com/o/oauth2/token%22%7D%7D&代码= 4 / x9MedwZ8NJN6qUgq2rXAVaBtFuOk.QpP5N0crfbAbYFZr95uygvVVqe1rjwI&安培; AUTHUSER = 0&安培; num_sessions = 1&安培; HD = veriyazilim.com.tr&安培; session_state = f715c83530f60300552e4920948401332014eeea..224b&安培;提示=无

enter image description here

 hello.init({
            google : '75055614045-a999nkehht0jk3i46548qg32imu0toqg.apps.googleusercontent.com'
        }, {
               redirect_uri : 'http://localhost/cevap/redirect.html',
            response_type:'code',
            scope:'friends'

        });

我在google中为Web应用程序创建了客户端ID。

enter image description here

这是我的文件夹定向:

enter image description here

2 个答案:

答案 0 :(得分:0)

在桌面浏览器中进行开发:

在注册您的应用时,需要一个与您定义为回调网址的域匹配的开发域 - 在redirect_uri中定义此回调网址,并确保它指向包含./hello.js的文档。

在您的情况下,此文件位于http:// localhost /cevap/redirect.html

对于phonegap来说,并非如此,因为应用程序以" file:// path / to / installed / apps / myproject"或者其他的东西。但是,phonegap应用程序可以查看它所引发的弹出窗口的URL,这就是hello.js如何从弹出窗口查询字符串中提取access_token的工作原理。在这种情况下,redirect_uri不需要是一个有效的路径,但为了获得更好的用户体验,我会指向一个可以显示类似旋转轮的Web资源。

答案 1 :(得分:-1)

问题不在url中。 inappbrowser无法加载到项目中。我将config.xml插件更改为此并且已加载inappbrowser并修复了问题。

<gap:plugin name="org.apache.cordova.inappbrowser" />