获取错误unsupported_response_type

时间:2015-06-01 11:22:35

标签: ionic-framework cordova-plugins ngcordova

我正在使用带有$ cordovaOauth.google插件的google功能登录。但是我收到了unsupported_response_type错误。

$cordovaOauth.google("MY_APP_ID", ["https://www.googleapis.com/auth/urlshortener", "https://www.googleapis.com/auth/userinfo.email"]).then(function (result) {
                console.log(JSON.stringify(result));
                alert(JSON.stringify(result));
                $scope.gdata = result;

            }, function (error) {
                console.log(error);
            });

我犯错误的地方!?

1 个答案:

答案 0 :(得分:0)

是的,因为$cordovaOauth插件加载了webview,因此您必须需要来自Google API的web clientID。这对离子(移动应用程序)不起作用,因此您需要做以下事情。

<强>第一

您需要使用应用的架构来提供内部网址,例如google://twitter://

参考: http://mcgivery.com/using-custom-url-schemes-ionic-framework-app/

并在Google重定向网址中提供该自定义网址(由于Google不接受自定义网址但您可以试一试,这不是一直有效。)

第二个和工作解决方案:

您需要使用应用标识符和keytool创建Google应用。

适用于Android:

https://developers.google.com/identity/sign-in/android/start按照第二步提供您的应用名称和唯一标识符(即dipesh.cool.com)

适用于iOS:

https://developers.google.com/mobile/add?platform=ios&cntapi=signin

与为Android提及的信息相同。

然后你需要从配置文件中获取REVERSED_CLIENT_ID值,一旦完成上述两个步骤,下载将可用(你可以从iOS配置文件中获取它,很容易从该文件中找到)。

然后只需在命令和代码下面运行,你就可以全部工作了。

命令:

cordova plugin add cordova-plugin-googleplus --variable REVERSED_CLIENT_ID=GRAB_THIS_FROM_IOS_OR_ANDROID_CONFIG_FILE

角色代码:

$scope.GoogleLogin = function()
{
    $scope.loaderShow('Google');
    window.plugins.googleplus.login({},function (obj)
    {
        window.localStorage.setItem('signin', 'Google');
        window.localStorage.setItem('g_uid', obj.userId);
        window.localStorage.setItem('g_fname', obj.givenName);
        window.localStorage.setItem('g_lname', obj.familyName);
        window.localStorage.setItem('user_full_name', obj.displayName);
        window.localStorage.setItem('g_email', obj.email);
        window.localStorage.setItem('gotPdetails', 'false');
        $scope.loaderHide();
        $state.go('app.dashboard');
    },
    function (msg)
    {
        $scope.showAlert('Google signin Error<br/>'+msg);
        $scope.loaderHide();
    });
}