Jump to content

Problems with Google Play Services


Todi
 Share

Recommended Posts

Hello guys,

So, I'm trying to implement the Google Play Services inside my game for the players challenge their friends with leaderboards scores and achievements. As I'm using Cordova, I have two ways: plugins or javascript libs. The first one is really old and limited, besides it not work well. And in the other hand we have the JS library of Google Web (REST) that you can find here https://developers.google.com/api-client-library/javascript/start/start-js and here https://developers.google.com/games/services/web/clientsetup. So, I'd tested both and the second is more interesting and complete than the first one.

However, I can't load the OAuth2 to start using the REST calls and complete my game logic. Reading about this, I discovered that the webview don't save cookies, and when I have not set the parameter cookie_policy to "none" I get this error:

Quote

Uncaught gapi.auth2.ExternallyVisibleError: Invalid cookiePolicy

And, when I set cookie_policy to "none", I have this error:

Quote

Failed to load resource: the server responded with a status of 400

I already have setup the lib in index.html

<!-- google play games service api -->
<script src="https://apis.google.com/js/client.js"></script>

And in my MainMenu state, I'm doing the SignIn tests using this code:

        // google play sign in
        if (gapi) {
            console.log('GAPI is loaded');
            gapi.client.setApiKey('<api_key>');
            gapi.load('client:auth2', function () {
                gapi.auth2.init({
                    client_id: '<client_id>',
                    cookie_policy: 'none',
                    scope: 'https://www.googleapis.com/auth/games'
                }).then(function () {
                    console.log('auth2 success');
                });
            });
        } else {
            console.error('GAPI is not loaded');
        }

I would like to know if anyone knows about how to implement GPGS using Cordova?! I'd like to understand what I'm doing wrong! Any help will be great!

Thank you!

Link to comment
Share on other sites

  • 9 months later...

This question was asked some time ago, but just in case anyone else comes across it, Google is killing OAuth from webviews (which Cordova runs in). So don't bother trying to get this to work. Google blog post about it is here: https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html

Your only option to add Google authentication to your Cordova app is to use OS-specific native code and then add some bridge code to your Cordova app.

Link to comment
Share on other sites

6 hours ago, Contra Code said:

This question was asked some time ago, but just in case anyone else comes across it, Google is killing OAuth from webviews (which Cordova runs in). So don't bother trying to get this to work. Google blog post about it is here: https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html

Your only option to add Google authentication to your Cordova app is to use OS-specific native code and then add some bridge code to your Cordova app.

Thanks! I knew it! In that time, I had to clone a Google Play Services project in Java and adapt to my desires. I released this game and it worked very well! :D

Link to comment
Share on other sites

Glad you were able to get it working! I did the same thing and went down dead-end paths for days before realizing that I needed to add Google Play Services to my project and then use a Cordova plugin.

 

For those who come across this post wondering what I used, I added the following to my project's build.gradle (not the app's build.gradle - the project build.gradle will say "Module: CordovaLib" in Android Studio) after the grouping of "apply plugin". If you include the entire suite of Google Play services, you may hit the maximum number of methods allowed for your app (there's a way around this called multi-dex, but don't bother), so only include a subset if you just want to add game services for leaderboards and such.

dependencies {
    compile 'com.google.android.gms:play-services-auth:10.2.6'
    compile 'com.google.android.gms:play-services-base:10.2.6'
    compile 'com.google.android.gms:play-services-analytics:10.2.6'
    compile 'com.google.android.gms:play-services-ads:10.2.6'
    compile 'com.google.android.gms:play-services-games:10.2.6'
}

 

And the Cordova plugin I'm using from npm is: cordova-plugin-play-games-services [ plugin website ]. The plugin hasn't been updated in a long time, but still works even with version 10.2.6 of Google Play Services.

Before starting to code though, set up the basic shell parts of your game in the Google Play Developer Console . You need the APP_ID from the Developer Console when installing the Cordova plugin above and the Console will allow you to list the test email accounts that can use your app before you publish.

And if you've been banging your head against the wall trying to get all of this to work, understand that's part of this process of getting it to work. :lol:

 

Edited by Contra Code
Clarification.
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...