简体   繁体   中英

Programmatically fetch user's last login date to G Suite

On a user's page on the G Suite admin console, an admin can see the last login of a user. For example, one user I can see has a "last login" date of two years ago.

I'm trying to pull this date programatically. However, the Reports API that provides information on login events only goes back 180 days . How is Google getting this login date, and can it be fetched via API?

Google has this information because they are logging the event when it happens and storing that to present in the admin console. If you start to build an application now and start storing those events as time passes you too will have a date that goes back years. G Suite Enterprise customers can seamlessly do this if they Set up BigQuery logs in the Admin console .

You should be able to get this information now though. Look at the following APIs used in GAMADV-XTD you can get this info with this command for example.

gam report users parameters accounts:last_login_time filters "accounts:last_login_time<#filtertime#" filtertime -5y

https://developers.google.com/admin-sdk/reports/v1/reference/activities https://developers.google.com/admin-sdk/reports/v1/reference/customerUsageReports https://developers.google.com/admin-sdk/reports/v1/reference/userUsageReport

I somehow missed this before, but you can get the last login date/time with the User Usage Report (rather than the Login Activity report).

API docs are here and the App Script example I'm using is here . I realized that if GAM was pulling the information there had to be an API for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM