1

My question is about GoogleConnect (with Codename One), but maybe it can be valid also for FacebookConnect.

The problem is that the following code gives me a token that changes every time: using the same username and password of Gmail, I get a different token after every login. So... how can I recognize the same user?

String token = GoogleConnect.getInstance().getAccessToken().getToken();
Francesco Galgani
  • 6,137
  • 3
  • 20
  • 23

1 Answers1

1

It seems I made the same mistake in recent materials. I need to update that code.

As explained here How to get the Facebook user id using the access token

You need to fetch the user id using this query https://graph.facebook.com/me?fields=id&access_token="xxxxx" and that will be the unique id you can store.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • And how to solve the same issue with Google inside a Codename One app? Here there are some instructions, but they need an external library and are suitable only on server side: https://developers.google.com/identity/sign-in/web/backend-auth At the moment I'm looking for a simpler approach. – Francesco Galgani Feb 06 '18 at 22:10
  • 1
    I haven't updated code to the newer Google login and mostly used Google+ login back then so I'm not sure but see this https://developers.google.com/+/web/api/rest/latest/people/get generally it says that `GET https://www.googleapis.com/plus/v1/people/me` should return the profile Google has for you when the authentication token is in place – Shai Almog Feb 07 '18 at 04:52
  • The informations here are very useful: http://www.codenameone.com/blog/building-a-chat-app-with-codename-one-part-2.html – Francesco Galgani Feb 07 '18 at 23:24