Google Play Games Services v2 (plugin beta)

Any news related to gpgs version 2 plugin?

My tests have all been successful, but the code for snapshots that I was using doesn’t work and needed updated. I’m trying to see how other testers results are going as I’m not privy to those communications.

Rob

Same here Rob.

Snapshots code doesn’t work and community really need it.

If there is a change in code or a workaround to make it work could you share it here please?

Please keep us updated if any news arise!

I’m happy to share the snapshot code from my test app. Again, it’s purely test code and my old code-pre-change once worked with the old plugin, so I can’t say this will work with the V1 plugin or not.

local myTable = { play = 1 } local snapshotFilename = "snapshot1" local data = json.encode( myTable ) local function gpgsSnapshotOpenForReadListener( event ) print( "snapshot open event:", json.prettify(event) ) if not event.isError then --local data = event.snapshot.contents.read() local data = gpgs.snapshots.getSnapshot (event.snapshotId) native.showAlert('Snapshots', 'Reading was ' .. (event.isError and 'unsuccessful' or 'successful') .. ',', { 'OK'}) end end local function gpgsSnapshotAfterSaveListener( event ) native.showAlert('Snapshots', 'Saving was ' .. (event.isError and 'unsuccessful' or 'successful') .. '.', {'OK'}) end local function openSnapshot() print("Opening snapshot") gpgs.snapshots.open({ filename = snapshotFilename, listener = gpgsSnapshotOpenForReadListener }) end local function gpgsSnapshotOpenForSaveListener( event ) print("open for save listener", json.prettify( event )) if not event.isError then local snapContent = gpgs.snapshots.getSnapshot(event.snapshotId).contents snapContent.write(data) -- Write new data as a JSON string into the snapshot gpgs.snapshots.save({ snapshotId = event.snapshotId, description = 'Save slot ' .. snapshotFilename, listener = gpgsSnapshotAfterSaveListener }) end end local function saveSnapshot() print("saving snapshhot") gpgs.snapshots.open({ -- Open the save slot filename = snapshotFilename, create = true, -- Create the snapshot if it's not found listener = gpgsSnapshotOpenForSaveListener }) end

There are still some issues we are working on with the testers so even if you managed to get access to the plugin when it was inadvertently made available, I still wouldn’t release against the V2 plugin until we say it’s ready.

Rob

I had this for gpgs version 1 and used to work (now it’s broken) like charm.

https://forums.coronalabs.com/topic/67896-how-to-implement-gpgs-plugin/

I can see the changes in your code but it would be better to make it work exactly as version 1.

Any chance for ETA? Days? Weeks?

This is tough to answer because “weeks” could mean anywhere between 2-8 weeks and I don’t think it will be anywhere in the 4-8 week range, but if I say “days”, in particular with the weekend in the way, it would set your expectations that it could be as early Monday or Tuesday and I don’t think that’s realistic either. 

Have you tried the code above with the V1 plugin?

Rob

I don’t know why the code from the link in my previous post stopped working the last weeks but I tried your code with ver1 plugin.

Did some changes and now I’m able to open snapshots.

Trying to do the same for saving snapshots too.

–edit

Saving works too, thnx Rob!

@Rob, any idea when this will be out of Beta?
FYI, my new app has about 500 installs with no ANRs and no crashes. You and your team deserves big time kudos!

@troylyndon we announced it last week. It’s not really in beta and should be a drop-in replacement. However, there are some reports on another thread of it not working. I would invite you to give it a try and help us identify if there are problems. Just make sure to test it before making a public release.

Rob

I am using gpgs v1. My snapshot functionality used to work before now it is not working anymore. No code changes were made from my side. Only the corona version was changed. 

I have tried gpgs v2 as a drop in replacement but the login pop up doesn’t even show and I can’t see any errors also so just reverted back to v1 again. 

Currently building with 2018.3397. 

Can you compare your snapshot code to this?
 

local myTable = { play = 1 } local snapshotFilename = "snapshot1" local data = json.encode( myTable ) local function gpgsSnapshotOpenForReadListener( event ) print( "snapshot open event:", json.prettify(event) ) if not event.isError then local data = event.snapshot.contents.read() native.showAlert('Snapshots', 'Reading was ' .. (event.isError and 'unsuccessful' or 'successful') .. ',', { 'OK'}) end end local function gpgsSnapshotAfterSaveListener( event ) native.showAlert('Snapshots', 'Saving was ' .. (event.isError and 'unsuccessful' or 'successful') .. '.', {'OK'}) end function myData.openSnapshot() print("Opening snapshot") gpgs.snapshots.open({ filename = snapshotFilename, listener = gpgsSnapshotOpenForReadListener }) end local function gpgsSnapshotOpenForSaveListener( event ) print("open for save listener", json.prettify( event )) if not event.isError then event.snapshot.contents.write(data) -- Write new data as a JSON string into the snapshot gpgs.snapshots.save({ snapshot = event.snapshot, description = 'Save slot ' .. snapshotFilename, listener = gpgsSnapshotAfterSaveListener }) end end function myData.saveSnapshot() print("saving snapshhot") gpgs.snapshots.open({ -- Open the save slot filename = snapshotFilename, create = true, -- Create the snapshot if it's not found listener = gpgsSnapshotOpenForSaveListener }) end

Apparently, there were multiple ways to do snapshots. 

Rob

@Rob

Yes my snapshot code is very similar to your one. The only difference is that I don’t have myData.savesnapshot() as a separate function. I have used the code of this how to implement gpgs post. 

During pre-launch test on developer console, one instance of an error was found, here is the message:
 

FATAL EXCEPTION: main Process: com.sheekore.games.sentioTapEmoji, PID: 12290 java.lang.NullPointerException: value == null     at java.util.Hashtable.put(Hashtable.java:362)     at plugin.gpgs.Utils.gameToHashtable(Utils.java:380)     at plugin.gpgs.Utils.snapshotMetadataToHashtable(Utils.java:444)     at plugin.gpgs.Snapshots$LoadSnapshotsResultCallback.onResult(Snapshots.java:412)     at plugin.gpgs.Snapshots$LoadSnapshotsResultCallback.onResult(Snapshots.java:389)     at com.google.android.gms.common.api.internal.BasePendingResult$CallbackHandler.handleMessage(Unknown Source)     at android.os.Handler.dispatchMessage(Handler.java:102)     at android.os.Looper.loop(Looper.java:148)     at android.app.ActivityThread.main(ActivityThread.java:5459)     at java.lang.reflect.Method.invoke(Native Method)     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

I don’t know where the snapshot code in that forum post originated, it almost looks like it’s your original code. The code I used to have wasn’t working either. The engineer who built the plugin provided me with the updated code which I tested with both V1 and V2 of the plugin. 

I’ll share this with Engineering.

Rob

@Rob

Thank you for having a look into this issue.

@Rob

I have updated the snapshot code. I am trying gpgs.v2 plugin, but it seems I can’t login. gpgs.isConnected() is giving false always but event.phase in gpgsLoginListener function is saying ‘logged in’. The pop up that normally used to show in gpgs V1 is not showing here. 

here is how I implemented the login functionality. With gpgs V1 it works but when I add v2, the login doesn’t work anymore. Are there any changes to be made?

local gpgs = require( "plugin.gpgs.v2" ) local function toggleGPGSToLogin( self, event ) &nbsp; if ( gpgs.isConnected() ) then &nbsp; &nbsp; gpgsLoggedOutButton.isVisible = false &nbsp; &nbsp; gpgsLoggedInButton.isVisible = true &nbsp; &nbsp; local tempGameData = loadsave.loadTable( "gameData.json" ) &nbsp; &nbsp; -- download snapshot &nbsp; &nbsp; local function gpgsSnapshotOpenForReadListener( event ) &nbsp; &nbsp; &nbsp; if not event.isError then &nbsp; &nbsp; &nbsp; &nbsp; -- local retrievedData = event.snapshot.contents.read()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local retrievedData = gpgs.snapshots.getSnapshot (event.snapshotId) &nbsp; &nbsp; &nbsp; &nbsp; local gameData, pos, msg = json.decode( retrievedData ) &nbsp; &nbsp; &nbsp; &nbsp; if not gameData then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; toast.show('Decoding failed.' ..tostring(pos)..": "..tostring(msg) )&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( tempGameData.inGameAnalyticsTotalGamePlayed \< gameData.inGameAnalyticsTotalGamePlayed&nbsp; ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- save table from the gpgs server &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loadsave.saveTable( gameData, "gameData.json" )&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- upload the offline gameplayed to GPGS server &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local gameData = loadsave.loadTable( "gameData.json" ) -- loading gameData from phone &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- save snapshots &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local function gpgsSnapshotOpenForSaveListener( event ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not event.isError then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local snapContent = gpgs.snapshots.getSnapshot(event.snapshotId).contents &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; snapContent.write( json.encode(gameData) ) -- Write new gameData as a JSON string into the snapshot &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gpgs.snapshots.save({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; snapshotId = event.snapshotId, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description = "Game scores", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image = { filename = "EmojiCrushShare.png", baseDir = system.ResourceDirectory }, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end -- gpgsSnapshotOpenForSaveListener func END &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gpgs.snapshots.open({&nbsp; -- Open the save slot &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filename = snapshotFileName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; create = true,&nbsp; -- Create the snapshot if it's not found &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conflictPolicy = "most recently modified", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; listener = gpgsSnapshotOpenForSaveListener &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end -- (tempInGameAnalytics.totalGamePlayed \< inGameAnalytics.totalGamePlayed)&nbsp; conditional END &nbsp; &nbsp; &nbsp; &nbsp; end -- not inGameAnalytics conditional END &nbsp; &nbsp; &nbsp; end -- event.iserror conditional END &nbsp; &nbsp; end --gpgsSnapshotOpenForReadListener func END &nbsp; &nbsp; gpgs.snapshots.open({ &nbsp; &nbsp; &nbsp; &nbsp; filename = snapshotFileName, &nbsp; &nbsp; &nbsp; &nbsp; conflictPolicy = "most recently modified", &nbsp; &nbsp; &nbsp; &nbsp; listener = gpgsSnapshotOpenForReadListener &nbsp; &nbsp; &nbsp; }) &nbsp; end -- gpgs.isConnected() conditional END end -- toggleGPGSToLogin func END local function gpgsLoginListener( event ) &nbsp; gameData.gpgsDataUserPref = event.phase &nbsp; print ("gpgsLoginListener") &nbsp; print (event.phase) &nbsp; loadsave.saveTable( gameData, "gameData.json" ) &nbsp; toggleGPGSToLogin() &nbsp; if event.isError then &nbsp; &nbsp; toast.show("Sign in problem: Check network connection.") &nbsp; end -- event.isError conditional END end local function onGpgsLoginButtonTap( self, event ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print ("onGpgsLoginButtonTap") &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print (gpgs.isConnected()) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (gpgs.isConnected()) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --logout &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gpgs.logout() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gameData.gpgsDataUserPref = "logged out" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loadsave.saveTable( gameData, "gameData.json" ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gpgsLoggedOutButton.isVisible = true &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gpgsLoggedInButton.isVisible = false &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --login &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gpgs.login( { userInitiated = true, listener = gpgsLoginListener } ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end -- login or logout conditional END &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true &nbsp; &nbsp; &nbsp; &nbsp; end -- onGpgsLoginButtonTap func END &nbsp; &nbsp; &nbsp; &nbsp; gpgsLoggedInButton:addEventListener( "tap", onGpgsLoginButtonTap ) &nbsp; &nbsp; &nbsp; &nbsp; gpgsLoggedOutButton:addEventListener( "tap", onGpgsLoginButtonTap )

Our engineer is investigating. It’s really weird because when I use a game I’m working on, it works as expected. When I change the credentials to something new, .isConnected() fails reliably. This leads me to believe that the new library from Google is dependent on a setting in the Google Play Console which wasn’t required with the v1 plugin.

Rob

Can everyone here give it another try? We pushed a possible fix for the .isConnected() API today.

Thanks

Rob

@Rob

I have built with 2018.3407

The login functionality is working,but now the achievements, leaderboards and snapshots are not working. even after log in. The default windows are not showing up for them.

 Code for achievements and leaderboards funcitonality:

local function handleButton(event) &nbsp; if (event.target.id == "inGameLeaderboards" and event.phase == "ended") then &nbsp; &nbsp; if (gpgs.isConnected()) then &nbsp; &nbsp; &nbsp; gpgs.leaderboards.show() &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; gpgs.login( { userInitiated = true, listener = gpgsLoginListener } ) &nbsp; &nbsp; &nbsp; gpgs.leaderboards.show() &nbsp; &nbsp; end -- gpgs is connected check outer END &nbsp; elseif (event.target.id == "inGameAchievements" and event.phase == "ended") then &nbsp; &nbsp; if (gpgs.isConnected()) then &nbsp; &nbsp; &nbsp; gpgs.achievements.show() &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; gpgs.login( { userInitiated = true, listener = gpgsLoginListener } ) &nbsp; &nbsp; &nbsp; gpgs.achievements.show() &nbsp; &nbsp; end -- gpgs is connected check outer END &nbsp; end -- button conditional END end

Code for snapshots upload and download funcitonality:

local function handleButton (event) &nbsp; if (event.target.id == "cloudUpload" and event.phase == "ended") then &nbsp; &nbsp; -- save snapshots &nbsp; &nbsp; local function gpgsSnapshotOpenForSaveListener( event ) &nbsp; &nbsp; &nbsp; if not event.isError then &nbsp; &nbsp; &nbsp; &nbsp; local snapContent = gpgs.snapshots.getSnapshot(event.snapshotId).contents &nbsp; &nbsp; &nbsp; &nbsp; snapContent.write( json.encode(gameData) ) -- Write new gameData as a JSON string into the snapshot &nbsp; &nbsp; &nbsp; &nbsp; gpgs.snapshots.save({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; snapshotId = event.snapshotId, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description = "Game scores", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image = { filename = "EmojiCrushShare.png", baseDir = system.ResourceDirectory }, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }) &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; end -- gpgsSnapshotOpenForSaveListener func END &nbsp; &nbsp; if (gpgs.isConnected()) then &nbsp; &nbsp; &nbsp; gpgs.snapshots.open({&nbsp; -- Open the save slot &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filename = snapshotFileName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; create = true,&nbsp; -- Create the snapshot if it's not found &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conflictPolicy = "most recently modified", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; listener = gpgsSnapshotOpenForSaveListener &nbsp; &nbsp; &nbsp; &nbsp; }) &nbsp; &nbsp; &nbsp; gpgs.snapshots.load( {reload = true, }) &nbsp; &nbsp; &nbsp; gpgs.snapshots.show( {title = "Emoji Crush", disableAdd = false, disableDelete = false}) &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; gpgs.login( { userInitiated = true, listener = gpgsLoginListener } ) &nbsp; &nbsp; &nbsp; gpgs.snapshots.open({&nbsp; -- Open the save slot &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filename = snapshotFileName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; create = true,&nbsp; -- Create the snapshot if it's not found &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conflictPolicy = "most recently modified", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; listener = gpgsSnapshotOpenForSaveListener &nbsp; &nbsp; &nbsp; &nbsp; }) &nbsp; &nbsp; &nbsp; gpgs.snapshots.load( {reload = true, }) &nbsp; &nbsp; &nbsp; gpgs.snapshots.show( {title = "Emoji Crush", disableAdd = false, disableDelete = false}) &nbsp; &nbsp; end -- gpgs is connected check outer END &nbsp; elseif (event.target.id == "cloudDownload" and event.phase == "ended") then &nbsp; &nbsp; -- download snapshot &nbsp; &nbsp; local function gpgsSnapshotOpenForReadListener( event ) &nbsp; &nbsp; &nbsp; if not event.isError then &nbsp; &nbsp; &nbsp; &nbsp; local retrievedData = gpgs.snapshots.getSnapshot (event.snapshotId) &nbsp; &nbsp; &nbsp; &nbsp; local gameData, pos, msg = json.decode( retrievedData ) &nbsp; &nbsp; &nbsp; &nbsp; if not gameData then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; toast.show('Decoding failed.' ..tostring(pos)..": "..tostring(msg))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loadsave.saveTable( gameData, "gameData.json" ) &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; -- DO NOTHING &nbsp; &nbsp; &nbsp; end -- event.iserror conditional END &nbsp; &nbsp; end --gpgsSnapshotOpenForReadListener func END &nbsp; &nbsp; if (gpgs.isConnected()) then &nbsp; &nbsp; &nbsp; gpgs.snapshots.open({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filename = snapshotFileName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conflictPolicy = "most recently modified", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; listener = gpgsSnapshotOpenForReadListener &nbsp; &nbsp; &nbsp; &nbsp; }) &nbsp; &nbsp; &nbsp; gpgs.snapshots.load( {reload = true, }) &nbsp; &nbsp; &nbsp; gpgs.snapshots.show( {title = "Emoji Crush", disableAdd = false, disableDelete = false}) &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; gpgs.login( { userInitiated = true, listener = gpgsLoginListener } ) &nbsp; &nbsp; &nbsp; gpgs.snapshots.open({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filename = snapshotFileName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conflictPolicy = "most recently modified", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; listener = gpgsSnapshotOpenForReadListener &nbsp; &nbsp; &nbsp; &nbsp; }) &nbsp; &nbsp; &nbsp; gpgs.snapshots.load( {reload = true, }) &nbsp; &nbsp; &nbsp; gpgs.snapshots.show( {title = "Emoji Crush", disableAdd = false, disableDelete = false}) &nbsp; &nbsp; end -- gpgs.isconnected END &nbsp; end-- conditional END

Hi Rob,

I’ve just rebuilt the game and tested it here. I got the same results. Nothing happens when calling gpgs.leaderboards.show() or gpgs.achievements.show().

Br,

Cleverson

Please see my post here. https://forums.coronalabs.com/topic/73999-from-the-blog-new-google-play-games-services-plugin/page-2#entry390218

Let’s keep the conversation there!

Thanks

Rob