使用cordova在android中添加google plus

时间:2015-01-06 11:25:11

标签: android cordova cordova-plugins

根据主题,我想使用cordova在android项目中添加google plus(API)。为此,我使用下面的链接教程cordova-plugin-googleplus。实际上我无法弄清楚这个问题,因为我正在根据iOS和Android两个教程做所有的镫骨。它的工作适用于iOS但不适用于Android。我有两个客户ID。 这是我的代码。

function login() {
    window.plugins.googleplus.login(
        {
                //'androidApiKey': 'demo2-f2piclv62253f0k177i3se3k30fcbqtq.apps.googleusercontent.com'
                'iOSApiKey': 'demo3462-f2piclv62253f0k177i3se3k30fcbqtq.apps.googleusercontent.com'
        },
        function (obj) {
            document.querySelector("#image").src = obj.imageUrl;
            document.querySelector("#image").style.visibility = 'visible';
            document.querySelector("#feedback").innerHTML = "Hi, " + obj.displayName + ", " + obj.email;
        },
        function (msg) {
            document.querySelector("#feedback").innerHTML = "error: " + msg;
        }
    );
}

enter image description here

1 个答案:

答案 0 :(得分:1)

最后我得到了解决方案,我正在使用cordova-plugin-googleplus插件,它适用于iOS,因为iOS clientId通过HTML传递。但对于Android,您必须以不同的方式传递ClientId。 对我来说:项目 - >插件 - > android.json

        "nl.x-services.plugins.googleplus": {
        "CLIENT_ID": "your_client_ID",
        "PACKAGE_NAME": "com.demo.googlelogin"
    }