Getting e-mail from GPGS

Hi there,

does anyone tried to get e-mail from google play services extension ? (I did it on unity projects, but defold don’t have all the data I need).

The only way I see is to override google Java methods, https://github.com/defold/extension-gpgs/blob/master/gpgs/src/java/com/defold/gpgs/GpgsJNI.java

and add the email auth to scope builder, and check if the user gave email permission.

Any other way ? don’t really want to override plugin standard methods/files.

thanks for advice,

You want to get the email address from the authenticated user?

Yes exactly

No other way. If you need more scopes the extension code has to change:

I’m thinking that it would be nice to add support for additional scopes in the extension somehow.

1 Like

ok thanks.
yes that would be great, better than editing google java files.

i’ll just override the java file and add the requestEmail to the google builder, for my case I just need the e-mail.

I’m stuck at this point :

i’ve added the requestEmail in the builder builder.requestEmail(); and the methods in gpgs/src/gpgs_extension.cpp to access getEmail(), as google doc https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInAccount#getEmail()

here is the fork : https://github.com/guycorpgames/extension-gpgs

any idea what I am missing ?

thanks,

mPlayer is of type Player, not GoogleSignInAccount.

ah of course…

It works now thanks !

I’ve updated the fork, maybe you want to use it, with a parameter in project to ask for e-mail or not.

the e-mail is accessible after sign in with gpgs.get_user_email()

example code :

function init(self)
	-- Add initialization code here
	-- Learn more: https://defold.com/manuals/script/
	-- Remove this function if not needed
	if gpgs then
		gpgs.set_callback(callback)
		gpgs.silent_login()
	end
end

function callback(self, message_id, message)
	if message_id == gpgs.MSG_SIGN_IN or message_id == gpgs.MSG_SILENT_SIGN_IN then
		if message.status == gpgs.STATUS_SUCCESS then
			-- do something after login
			print(gpgs.get_display_name())
			print(gpgs.get_user_email())
		end
	elseif message_id == gpgs.MSG_SIGN_OUT then
		-- do something after logout
	elseif message_id == gpgs.MSG_LOAD_SNAPSHOT then
		-- do something when a save was loaded
	end
end
1 Like

Nice! We should define a number of different auth scope constants and allow the user to pass in a list of scopes at login.