Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Not connected GPGS v2
Started by oliver.kjellen Feb 23 2019 12:53 PM

32 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

oliver.kjellen

[GLOBAL: userInfoPane.html]
oliver.kjellen
  • Observer

  • 24 posts
  • Corona SDK

Hi!

 

I've been struggling with this for a few days now to no avail. I'll post the code below but in short I'm following the tutorial found in the docs. When I'm later trying to show the leaderboards or submit a score to said leaderboards I get an error in the terminal saying that gpgs are not connected despite a successful login at launch. Is there something I'm missing with the new V2 pluggin?

local globalData = require( "globalData" )
local json = require( "json" )

globalData.gpgs = nil

local platform = system.getInfo( "platform" )
local env = system.getInfo( "environment" )
 
if ( platform == "android" and env ~= "simulator" ) then
    globalData.gpgs = require( "plugin.gpgs.v2" )
end

local function gpgsInitListener( event )
    if not event.isError then
        if ( event.name == "init" ) then  -- Initialization event
            -- Attempt to log in the user
            print( json.prettify(event) )
 
        elseif ( event.name == "login" ) then  -- Successful login event
            print( json.prettify(event) )
        end
    end
end

if ( globalData.gpgs ) then
    -- Initialize Google Play Games Services
    globalData.gpgs.login( { userInitiated=true, listener=gpgsInitListener } )
end

sometime later:

function showLeaderBoards()
	print("leader")
	if ( globalData.gpgs ) then
        		globalData.gpgs.leaderboards.show()
                 print( json.prettify(event) )
       	end
end

cupPress:addEventListener( "tap", showLeaderBoards)

Here I get the gpgs: not connected error.

 

Any help would be much appreciated! :)



[TOPIC: post.html]
#2

bgmadclown

[GLOBAL: userInfoPane.html]
bgmadclown
  • Contributor

  • 706 posts
  • Corona SDK

I'm also having the same problem but some people say their problems are solved when they manually activate the following APIs: Drive API and Google Play Developer API.

 

If you enabled those, you are probably having the same issue as me. No errors thrown, event.phase is "logged in" but the player is neither connected nor authenticated.


Edited by bgmadclown, 24 February 2019 - 07:07 AM.


[TOPIC: post.html]
#3

schizoid2k

[GLOBAL: userInfoPane.html]
schizoid2k
  • Contributor

  • 578 posts
  • Corona SDK

As a test, I would remove the check for event.isError to see if you can connect.

I tend to use isConnected() when I attempt a GPGS call.



[TOPIC: post.html]
#4

stamosgi

[GLOBAL: userInfoPane.html]
stamosgi
  • Observer

  • 4 posts
  • Corona SDK

Same here.

 

The weird thing is I'm sharing a big part of the code in 4 different games.

 

The one game connects and shows leaderboard as it should, the other three won't. With the same code.

I'm not using the isConnected parameter but it shouldn't be a problem since my first game actually connects.

 

Using release keystore.

I've enabled all the necessary APIs.

Double and triple checked my authentication parameters.

Tried with latest public build and two fifferent daily builds.

 

I can see on adb logcat the "logged in" event but when I call leaderboards.show I get "plugin.gpgs. not connected".

 

One thing I find weird is that in the first game that leaderboards do work, abd logcat gives me two "logged in" events in a row.

But the other three games that leaderboards don't work, I only get one "logeed in" event.



[TOPIC: post.html]
#5

oliver.kjellen

[GLOBAL: userInfoPane.html]
oliver.kjellen
  • Observer

  • 24 posts
  • Corona SDK

Well, I've been trying to get this to work for 2 days now with no success. Has anyone else resolved this?  :wacko:



[TOPIC: post.html]
#6

oliver.kjellen

[GLOBAL: userInfoPane.html]
oliver.kjellen
  • Observer

  • 24 posts
  • Corona SDK

Still struggling, looking at the requests received by the drive api they all result in errors.



[TOPIC: post.html]
#7

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,680 posts
  • Enterprise

I wish I had an answer for you. This is working as expected in my game. I wish Google didn't make setting things up so difficult. I'm going to post the settings for my game along with some notes:

 

First my build.settings "android" section:

	android =
	{
		googlePlayGamesAppId = "249XXXXXXX34", -- this has to match what is online
		facebookAppId = "16XXXXXXXXXXXX61",
		usesPermissions =
		{
			"com.android.vending.BILLING",
			"com.android.vending.CHECK_LICENSE",
			"android.permission.INTERNET",
			"android.permission.VIBRATE",
			"android.permission.WRITE_EXTERNAL_STORAGE",
			"android.permission.ACCESS_NETWORK_STATE", -- needed for the vungle plugin
		},
		supportsScreens =
		{
			resizeableActivity = false,
			smallScreens  = true,
			normalScreens = true,
			largeScreens  = true,
			xlargeScreens = true,
		},
	},

Go to the Game Services tab and find your game there:

Attached File  Screen Shot 2019-02-26 at 2.53.14 PM.png   217.75KB   4 downloads

 

Click on your game to get the value for googlePlayGamesAppId. Even though it looks like a number, make it a string!

Attached File  Screen Shot 2019-02-26 at 2.53.34 PM.png   23.21KB   3 downloads

 

Scroll to the bottom and make sure you have green checkmarks here:

Attached File  Screen Shot 2019-02-26 at 2.54.16 PM.png   85.76KB   4 downloads

Check on the linked app section and make sure your real game is linked. Both are likely sharing similar names.

Attached File  Screen Shot 2019-02-26 at 2.54.34 PM.png   332.7KB   3 downloads

 

Make sure you have a leaderboard added and published.

Attached File  Screen Shot 2019-02-26 at 2.55.02 PM.png   388.28KB   2 downloads

 

Finally, make sure you have no "triangle" "todo" logos here:

Attached File  Screen Shot 2019-02-26 at 2.56.07 PM.png   56.49KB   3 downloads

 

Then follow the tutorial on adding leaderboards to your app. My code will be a little different than the tutorial (but the tutorial was based on this and made more generic).

myData.gpgs = nil

print("platform: ", myData.platform, system.getInfo("environment"))
if "android" == myData.platform and "simulator" ~= system.getInfo("environment") then
	print("requiring GPGS")
	myData.gpgs = require("plugin.gpgs.v2")
end

local function gpgsLoginListener( event )
	print("*** gpgsLoginListener ***")
	print( json.prettify( event ) )
 
	if not event.isError then
		if ( event.name == "login" ) then  -- Successful login event
			myData.isGameNetworkingLoggedIn = true
			print("I think isConnected() is", myData.gpgs.isConnected())
		end
	end

end

if myData.gpgs then
	print("Initializing GPGS")
	--myData.gpgs.init( gpgsInitListener )
	myData.gpgs.login( { userInitiated=true, listener=gpgsLoginListener } )
end

For testing purposes, I added a button to my UI to set a high score. It's hard to test this through normal game play because getting a new high score is tough.

	local function gcSubmitScoreListener()
		print("submitted")
	end

	local gpgsSetHighScoreButton = widget.newButton({
		label = "Set High Score",
		onRelease = function( event )
			myData.settings.highScore = myData.settings.highScore + 100000
			myData.gpgs.leaderboards.submit({ leaderboardId = "CgkXXXXXXXXXXXXQBg", score = myData.settings.highScore, listener = gcSubmitScoreListener } )
			end,
		})
	sceneGroup:insert(gpgsSetHighScoreButton)
	gpgsSetHighScoreButton.x = display.contentWidth - 50
	gpgsSetHighScoreButton.y = display.contentHeight - 20

Then to show the score:
 

local function gameNetworkingLeaderboards()
	print("*** gameNetworking leaderboards ***")
	if myData.gameNetwork then
		print("*** gameNetwork: attempting to call show leaderboard")
		myData.gameNetwork.show( "leaderboards",
		{
			leaderboard = {
				category = "com.myawesomegame.leaderboard"
			},
			listener = showLeaders
		})
	elseif myData.gameCenter then 
		print("*** gameCenter leaderboards")
		myData.gameCenter.leaderboards.show("com.myawesomegame.leaderboard")
	elseif myData.gpgs then
		print("*** GPGS trying to show GPGS leaderboard", myData.gpgs.isConnected())
		myData.gpgs.leaderboards.show( )
	end
end

This works for me. Did I get everything above? Who knows. Google keeps changing things and making it hard to find all the settings.

Can you copy/paste this code? Not a chance because you're likely not using the same faux globals table I'm using. My ID's have been masked. You likely have named functions differently.

But this works.

 



[TOPIC: post.html]
#8

oliver.kjellen

[GLOBAL: userInfoPane.html]
oliver.kjellen
  • Observer

  • 24 posts
  • Corona SDK

I wish I had an answer for you. This is working as expected in my game. I wish Google didn't make setting things up so difficult. I'm going to post the settings for my game along with some notes:

 

First my build.settings "android" section:

	android =
	{
		googlePlayGamesAppId = "249XXXXXXX34", -- this has to match what is online
		facebookAppId = "16XXXXXXXXXXXX61",
		usesPermissions =
		{
			"com.android.vending.BILLING",
			"com.android.vending.CHECK_LICENSE",
			"android.permission.INTERNET",
			"android.permission.VIBRATE",
			"android.permission.WRITE_EXTERNAL_STORAGE",
			"android.permission.ACCESS_NETWORK_STATE", -- needed for the vungle plugin
		},
		supportsScreens =
		{
			resizeableActivity = false,
			smallScreens  = true,
			normalScreens = true,
			largeScreens  = true,
			xlargeScreens = true,
		},
	},

Go to the Game Services tab and find your game there:

attachicon.gifScreen Shot 2019-02-26 at 2.53.14 PM.png

 

Click on your game to get the value for googlePlayGamesAppId. Even though it looks like a number, make it a string!

attachicon.gifScreen Shot 2019-02-26 at 2.53.34 PM.png

 

Scroll to the bottom and make sure you have green checkmarks here:

attachicon.gifScreen Shot 2019-02-26 at 2.54.16 PM.png

Check on the linked app section and make sure your real game is linked. Both are likely sharing similar names.

attachicon.gifScreen Shot 2019-02-26 at 2.54.34 PM.png

 

Make sure you have a leaderboard added and published.

attachicon.gifScreen Shot 2019-02-26 at 2.55.02 PM.png

 

Finally, make sure you have no "triangle" "todo" logos here:

attachicon.gifScreen Shot 2019-02-26 at 2.56.07 PM.png

 

Then follow the tutorial on adding leaderboards to your app. My code will be a little different than the tutorial (but the tutorial was based on this and made more generic).

myData.gpgs = nil

print("platform: ", myData.platform, system.getInfo("environment"))
if "android" == myData.platform and "simulator" ~= system.getInfo("environment") then
	print("requiring GPGS")
	myData.gpgs = require("plugin.gpgs.v2")
end

local function gpgsLoginListener( event )
	print("*** gpgsLoginListener ***")
	print( json.prettify( event ) )
 
	if not event.isError then
		if ( event.name == "login" ) then  -- Successful login event
			myData.isGameNetworkingLoggedIn = true
			print("I think isConnected() is", myData.gpgs.isConnected())
		end
	end

end

if myData.gpgs then
	print("Initializing GPGS")
	--myData.gpgs.init( gpgsInitListener )
	myData.gpgs.login( { userInitiated=true, listener=gpgsLoginListener } )
end

For testing purposes, I added a button to my UI to set a high score. It's hard to test this through normal game play because getting a new high score is tough.

	local function gcSubmitScoreListener()
		print("submitted")
	end

	local gpgsSetHighScoreButton = widget.newButton({
		label = "Set High Score",
		onRelease = function( event )
			myData.settings.highScore = myData.settings.highScore + 100000
			myData.gpgs.leaderboards.submit({ leaderboardId = "CgkXXXXXXXXXXXXQBg", score = myData.settings.highScore, listener = gcSubmitScoreListener } )
			end,
		})
	sceneGroup:insert(gpgsSetHighScoreButton)
	gpgsSetHighScoreButton.x = display.contentWidth - 50
	gpgsSetHighScoreButton.y = display.contentHeight - 20

Then to show the score:
 

local function gameNetworkingLeaderboards()
	print("*** gameNetworking leaderboards ***")
	if myData.gameNetwork then
		print("*** gameNetwork: attempting to call show leaderboard")
		myData.gameNetwork.show( "leaderboards",
		{
			leaderboard = {
				category = "com.myawesomegame.leaderboard"
			},
			listener = showLeaders
		})
	elseif myData.gameCenter then 
		print("*** gameCenter leaderboards")
		myData.gameCenter.leaderboards.show("com.myawesomegame.leaderboard")
	elseif myData.gpgs then
		print("*** GPGS trying to show GPGS leaderboard", myData.gpgs.isConnected())
		myData.gpgs.leaderboards.show( )
	end
end

This works for me. Did I get everything above? Who knows. Google keeps changing things and making it hard to find all the settings.

Can you copy/paste this code? Not a chance because you're likely not using the same faux globals table I'm using. My ID's have been masked. You likely have named functions differently.

But this works.

Thanks for the answer! I'll go through my game again to make sure it's all setup correctly and hopefully I'll be able to solve it.

 

What's odd though is that the code I'm using now works for another game that I published a while back. Was the application above built recently? I'm curious to see if it works if you build a new application now, if it's not too much trouble of course. If it still works after that then it should be something wrong on my end.  :wacko:



[TOPIC: post.html]
#9

bgmadclown

[GLOBAL: userInfoPane.html]
bgmadclown
  • Contributor

  • 706 posts
  • Corona SDK

I published the leaderboard but it still fails. I guess I'll try a different solution.



[TOPIC: post.html]
#10

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,680 posts
  • Enterprise

Administrative note: Please don't quote whole messages when they are particularly long or has images.

 

Thanks

Rob



[TOPIC: post.html]
#11

bgmadclown

[GLOBAL: userInfoPane.html]
bgmadclown
  • Contributor

  • 706 posts
  • Corona SDK

Sorry that I forgot to mention some details.

 

1- APIs required part doesn't show me to enable Drive API but I enabled it anyway. Even though it's enabled and not required for simple login to work, I still get errors for Drive API on the console. I'm assuming pinging Drive API is a plugin thing but I'm not sure if it's related to the problem we're having.

 

2- I'm not sure if it's a Google thing or a plugin thing but we shouldn't be seeing the "logged in" phase when GPGS is not connected nor authenticated. We should be seeing a "login fail" state or an event error with an error message to why it failed but the event returns no errors with a "logged in" flag even though we're not.



[TOPIC: post.html]
#12

oliver.kjellen

[GLOBAL: userInfoPane.html]
oliver.kjellen
  • Observer

  • 24 posts
  • Corona SDK

I've been restarting from scratch a few times now setting up the game in the play console and so on. Still no success, is it possible to use the old plugin gpgs (v1)? When I try to use the old plugin the game crashes on launch unfortunately.

I really need to get this update pushed soon if possible  :)



[TOPIC: post.html]
#13

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,680 posts
  • Enterprise

You can try and use the old plugin, but it's dependent on the Google Plus login scope.

 

Rob



[TOPIC: post.html]
#14

gorosoft

[GLOBAL: userInfoPane.html]
gorosoft
  • Observer

  • 23 posts
  • Corona SDK

You can try and use the old plugin, but it's dependent on the Google Plus login scope.

 

Rob

 

No Rob, i'm afraid old plugin is not working, it always receives "8 internal error" even though i'm using same code than other game which is working with old plugin, that was my reason to move to gpgs.v2 plugin but also i'm receiving a gpgs.v2 "not connected" in adb.

 

Days and days debugging and trying workarounds and there is no way of use gpgs on a game, maybe because it doesn't depend on us... but it's awful.



[TOPIC: post.html]
#15

gorosoft

[GLOBAL: userInfoPane.html]
gorosoft
  • Observer

  • 23 posts
  • Corona SDK

Still struggling, looking at the requests received by the drive api they all result in errors.

 

Me too, could this be the reason of "not connected" error?



[TOPIC: post.html]
#16

gorosoft

[GLOBAL: userInfoPane.html]
gorosoft
  • Observer

  • 23 posts
  • Corona SDK

No Rob, i'm afraid old plugin is not working, it always receives "8 internal error" even though i'm using same code than other game which is working with old plugin, that was my reason to move to gpgs.v2 plugin but also i'm receiving a gpgs.v2 "not connected" in adb.

 

Days and days debugging and trying workarounds and there is no way of use gpgs on a game, maybe because it doesn't depend on us... but it's awful.

 

For all you to know, i removed my linked app from the game services that i was trying to connect and i have linked it to a game in my game services that i was using (and working) and just changing the googlePlayGamesAppId in my build settings ... it works (with gpgs v1). 



[TOPIC: post.html]
#17

stamosgi

[GLOBAL: userInfoPane.html]
stamosgi
  • Observer

  • 4 posts
  • Corona SDK

I did the same change as gorosoft above and it worked for me too. Using gpgs.v2 in my case.

 

But unfortunately this can not be considered as a permanent solution.

Now that the leaderboard does open, but it gives you the choice to open all the leaderboards of the other linked games.

 

So if i have 10 linked games and use this method to finally get the leaderboards working, I will end up with a player who wants to check his standing but instead gets frustrated from having to find the right board from the list.

 

It will be confusing and ultimately cause the player to see it as a disturbance.

 

In general I am very dissapointed.

I have 6 android studio apps all working fine.

2 unity apps working fine as well.

I only face this issue with corona and no matter what I do there is no solution, since it doesn't seem to be a problem with corona.

 

I hope someone comes up with an idea before I give it up because I am very close to that point.



[TOPIC: post.html]
#18

bgmadclown

[GLOBAL: userInfoPane.html]
bgmadclown
  • Contributor

  • 706 posts
  • Corona SDK

I already gave up and trying some php/mySQL solution to setup my own leaderboard at the moment because it seems that Corona doesn't have any plans to look into this in the near future. That's what I got from Rob's answers above. I'd advice you follow the same route.

By the way, I don't think GPGS v1 can be considered a reliable solution because, as far as I can remember, people were reporting many ANRs and crashes related to that version.


Edited by bgmadclown, 04 March 2019 - 04:04 AM.


[TOPIC: post.html]
#19

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,680 posts
  • Enterprise

That's not quite 100% correct. I'm trying to build a fresh app that uses the GPGSv2 plugin to see if I can find the trigger as to why some apps work and others do not.

 

Now that said, I believe GPGS has a REST API and if you're just wanting leaderboards, it might be a simpler approach. But I am trying to track down the difference.

 

Rob



[TOPIC: post.html]
#20

mysticeti

[GLOBAL: userInfoPane.html]
mysticeti
  • Contributor

  • 143 posts
  • Corona SDK

@Rob

 

I am getting some errors in isAuthenticated() method of gpgs v2. Here is the link to the full error report. This error happen when in the user is logged out and any gpgs calls gives runtime error.  :(



[TOPIC: post.html]
#21

gorosoft

[GLOBAL: userInfoPane.html]
gorosoft
  • Observer

  • 23 posts
  • Corona SDK

I did the same change as gorosoft above and it worked for me too. Using gpgs.v2 in my case.

 

But unfortunately this can not be considered as a permanent solution.

Now that the leaderboard does open, but it gives you the choice to open all the leaderboards of the other linked games.

 

So if i have 10 linked games and use this method to finally get the leaderboards working, I will end up with a player who wants to check his standing but instead gets frustrated from having to find the right board from the list.

 

It will be confusing and ultimately cause the player to see it as a disturbance.

 

In general I am very dissapointed.

I have 6 android studio apps all working fine.

2 unity apps working fine as well.

I only face this issue with corona and no matter what I do there is no solution, since it doesn't seem to be a problem with corona.

 

I hope someone comes up with an idea before I give it up because I am very close to that point.

 

Yes, same for me, now i have 2 leatherboards... and also, good to know that android studio and unity apps are working fine, maybe it's time to try unity and leave corona apart for a while till this issue is solved.

 

@bgmadclown, thank you for the info about GPGS v1 and ARN and crashes.



[TOPIC: post.html]
#22

gorosoft

[GLOBAL: userInfoPane.html]
gorosoft
  • Observer

  • 23 posts
  • Corona SDK

That's not quite 100% correct. I'm trying to build a fresh app that uses the GPGSv2 plugin to see if I can find the trigger as to why some apps work and others do not.

 

Now that said, I believe GPGS has a REST API and if you're just wanting leaderboards, it might be a simpler approach. But I am trying to track down the difference.

 

Rob

 

Rob, I think that you won't be able to make it work as long as you use a NEW game services play, if you do, it would be great, but it is not only about leaderboards but also about realtime multiplayer, at least in my case.

 

I'm really hoping that you find out why we are getting "not connected" from gpgs



[TOPIC: post.html]
#23

Aarbron

[GLOBAL: userInfoPane.html]
Aarbron
  • Contributor

  • 221 posts
  • Corona SDK

Hello.

Im having the same issues with gpgs version 2.

 

How do we manually activate Drive API and Google Play Developer API?



[TOPIC: post.html]
#24

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,680 posts
  • Enterprise

Here is the test code I used with the developer of the GPGS v2 plugin to test snapshots. It's geared to the way I do things with a faux global table and my internals, so you can't just copy/paste this code. You will need to modify it to your use:

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")
	myData.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
		myData.gpgs.snapshots.save({
			snapshot = event.snapshot,
			description = 'Save slot ' .. snapshotFilename,
			listener = gpgsSnapshotAfterSaveListener
		})
	end
end

function myData.saveSnapshot()
	print("saving snapshhot")
	myData.gpgs.snapshots.open({ -- Open the save slot
		filename = snapshotFilename,
		create = true, -- Create the snapshot if it's not found
		listener = gpgsSnapshotOpenForSaveListener
	})
end

if myData.gpgs then
print("Initializing GPGS")
--myData.gpgs.init( gpgsInitListener )
myData.gpgs.login( { userInitiated=true, listener=gpgsLoginListener } )
end

It looks like I've deleted the code to actually call these functions, but it should be pretty obvious how to use them.



[TOPIC: post.html]
#25

Aarbron

[GLOBAL: userInfoPane.html]
Aarbron
  • Contributor

  • 221 posts
  • Corona SDK

Hello Rob!

 

My main problem is that I can't even connect using gpgs v2.

My apps are working fine with version 1 for years.

 

APIs have green marks as you said and everything works fine with version 1.

 

Also my code is exactly the same as yours.

 

Some help please!

 

edit:

Should I update the OAuth 2.0 protocol manually?




[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]