getting blank name (display name) from google plus api - google-api

I am working on login system where user is logged to website using google plus api . I am hitting "me" endpoint after token verification .But I am facing a problem in some cases where I don't get the displayName/Name object of the user .
scopes used : plus.profile and plus.login
Endpint hit : "me"
$service=new Google_Service_Plus($client);
$userinfo=$service->people->get('me');
I want to fetch the username of the user .

Google+ Sign-In provides support for all users with a Google account, even if they have not yet created a Google+ profile. Your app can either prompt those users to create a Google+ profile (by using the https://www.googleapis.com/auth/plus.login scope) or not (by using the profile scope)
Switch to Google+ Sign-In
If you use the https://www.googleapis.com/auth/plus.login scope, users are guaranteed to have a Google+ profile.

If you want to bring information about the profile (Names) and Email.
I'd recommed you add the follow scopes separated by two spaces:
profile email
profile bring the Names (givenName, familyName, etc.) and email bring the email.

Related

Create a profile after user signs in Firebase and SwiftUI

The app should:
create new profile with email or Google Sign-In or Facebook Login
after creating the profile there is an email verification and then the user can sign in
if is the first time it should show a page to create a new in-app profile (creating a document in the database with the uid of the user with description, skills...)
but in this page if the user Google Sign-In it should show name and surname and the Google profile picture and let them add additional info such as description and their skills...
The first 2 steps are easy to achieve but how can I understand if the user just created the profile or he just logged out and in again or he simply uses Google Sign-In every time. And how can I take the user info from the database in Firebase and show it in the create in-app profile page.
Is it possible to achieve in SwiftUI?
Thanks!
To detect is a signed-in user is new, you can compare lastSignInDate and creationDate in the UserMetadata object.
Also see:
Get Created date and last login date from FIRUser with Firebase 3
iOS/Swift/Firebase Authentication: Help Needed on Accessing "isNewUser", which shows the isNewUser that you can also sometimes use (depending on your implementation).

How to replace people.me from Google+ with Google People/Google Sign In api?

I had a "sign in with Google+" function in my web-app. Upon signing in I would show user's email and name on the page and save it to database. To fetch user's profile data after sign in I used Google+ API method people.me with access_token in GET params.
Google+ API is going to shut down on March 7. I have to migrate to Google People or some other api. How do I achieve the same goal with a different google API? I need to fetch email and name by known auth token.
We use this through Laravel's Socialite, and they're replacing it with:
https://www.googleapis.com/userinfo/v2/me
You may want the profile scope as part of the OAuth flow to make the profile data accessible through this methods. Otherwise it will return incomplete data.

Can I use single Google API credential for multiple deployed microservices for same user on different instances?

Application1 -> Microservice1 (deployed on one server, also db is separate)
Application2 -> Microservice2 (deployed on other server, also db is separate)
NOTE : For Microservice1 and Microservice2 we are use same Google API credentials.
We have a one application in that we are providing user to edit it's word, ppt, excel files with Online editor.
So, we have configure Microservice which used GSuite API for user to edit there file with google online word editor.
Now, we have a scenario like when one user open file from Application1 then our application will redirect user to google login screen and once user enter it's credentials then google will check whether third-party application already registered with login user account or not, and if not then google will give consent screen to register third-party app with current user.
Once user allow third-party app then google will redirect user to our Microservice1
once callback came to our Microservice then we will store user's refresh-token to our db and user can able to edit document online.
Now, user open file from Application2 and it will redirect user to google login screen and once user enter it's same credentials which he used in above then google will check whether third-party application already registered with login user account or not, this time google found that third-party application already registered with them, and google will redirect user to Microservice2, but this time google doesn't give refresh-token and in our db also refresh-token entry not there, so we will not able to open the file in online editor.
So, is there any way to handle these kind of scenario with only single Google API Credential?
Or we need separate account which give us different Google API Credentials?
Like :
Microservice1 (One Google Account with Google API Credential)
Microservice2 (Another Google Account with Google API Credential)
Any kind of help appreciated.
Thanks in advance...
you need to create a service account, possibly with G Suite Domain-Wide Delegation of Authority.

Can't read phone numbers from user's google profile using - auth/user.phonenumbers.read scope

Based on the documentation of Google People API I am using profile scope - https://www.googleapis.com/auth/user.phonenumbers.read and PersonFields=phoneNumbers to read the authenticated user's phone numbers only in their Google profile (none from the contact list). I am using API key and oAuth accesstoken to authorise the request. The google people API is not fetching the phone numbers associated with the profile with the above scope alone. Adding the scope for the entire contact list read access in addition to the above scope, which is www.googleapis.com/auth/contacts.readonly returns the phone numbers from the profile correctly. Is there any way to get user's phone numbers from his/her profile using only the user.phonenumbers.read scope?
I could figure out the problem. For 'user.phonenumbers.read' scope the documentation of people API states - 'your app be given read access to the authenticated user's phone numbers in their Google profile'.
But by 'Google profile' it indicates the Google Plus Profile which is completely different form their core google profile - My Account. People API is fetching information only from the Google Plus Profile.
So even if a user has his/her contact details added in My Account, the People API will not fetch their phone numbers unless they have added them manually in their Google Plus Profile. After adding the contact details I could fetch contact details with 'auth/user.phonenumbers.read' without the need of adding 'auth/contacts.readonly' scope.

add calendar to another user's calendar list

Not sure if this is possible or if anyone has managed to do this. I have user with super admin access, with which I can create a new user for my domain. However I also want to add a couple of calenders to the created user's calendar list. When I create a user I authenticate using my super admin, but then I can't add a calendar to the user's calendar list since I am not logged in as the user. Is it possible to do this as the super admin, or do I have to logout and authenticate as the created user in order to add calendars to their list? This is the base url to which the post request is made:
https://www.googleapis.com/calendar/v3/users/me/calendarList
in the place of me could I pass in the id of the user? I couldn't find any parameter in the documentation with which I can specify the user to whose list I want to add a calender.
Thanks
Two options:
Each user much login to google calendar and share thier calendar to a single user. You can then use this account to update their calendars. Note that google has limitations to how many calendars and request you are allowed before the account goes to read-only mode.
Buy a google apps domain (5$per user per month) and create a service account at console.developers.google.com. Create a project and give it domain wide delgation at admin.google.com. In Apps engine you should be able to give access for admin to modify all users calendars.
No matter what case you choose, you also need to enable CalendarAPI at dev console site. Now with private key created from website request OAuth2 access token, where sub field is set for the users that you want to change calendar for. With returned access token use CalendarAPI to modify calendar.
Sry for bad english and short description, i'm in a hurry. /conner ;)

Resources