GSuite - Last email activity - google-admin-sdk

I am trying to create a GSuite integration using GSuite Admin SDK that will fetch a list of users and the datetime of their last activity. I am able to fetch last login time, but I can't find a way to find the last email activity for a user that uses POP or IMAP email clients.
The data that I am trying to fetch is available in the admin console:
But is there a way to fetch it using Gsuite Admin SDK?

I found a solution to get the email activities for users, but the examples in the API reference were not so straight-forward, and they were spread out on several pages. I ended up using User Usage Report from the GSuite Reports API (as suggested in a comment on the original question): https://developers.google.com/admin-sdk/reports/v1/guides/manage-usage-users
Sample call:
GET https://www.googleapis.com/admin/reports/v1/usage/users/all/dates/2018-05-21?parameters=classroom:last_interaction_time,accounts:last_login_time,accounts:last_sso_time,gmail:last_access_time,gmail:last_imap_time,gmail:last_interaction_time,gmail:last_pop_time,gmail:last_webmail_time
This way I was able to get not only email activities, but also Classroom last interaction time and GSuite last login time and Last SSO time.
Sample user response:
"entity": {
"type": "USER",
"customerId": "customerId",
"userEmail": "sample#email.com",
"profileId": "profileId"
},
"parameters": [
{
"name": "classroom:last_interaction_time",
"datetimeValue": "1970-01-01T00:00:00.000Z"
},
{
"name": "accounts:last_login_time",
"datetimeValue": "2018-05-18T14:46:11.000Z"
},
{
"name": "accounts:last_sso_time",
"datetimeValue": "1970-01-01T00:00:00.000Z"
},
{
"name": "gmail:last_access_time",
"datetimeValue": "2018-05-18T08:43:15.000Z"
},
{
"name": "gmail:last_imap_time",
"datetimeValue": "1970-01-01T00:00:00.000Z"
},
{
"name": "gmail:last_interaction_time",
"datetimeValue": "2018-04-23T07:08:40.000Z"
},
{
"name": "gmail:last_pop_time",
"datetimeValue": "1970-01-01T00:00:00.000Z"
},
{
"name": "gmail:last_webmail_time",
"datetimeValue": "2018-04-23T07:08:44.000Z"
}
]

Related

Facebook (Instagram) Graph API not returning instagram_business_account

First of all, let me explain what I have today:
I have a access token with the following permissions: email, public_profile, pages_show_list, pages_read_engagement, instagram_basic, instagram_manage_insights
I have a valid access token
The accounts that I'm trying to access are Business Account or Content Creator account
With that in mind, here's my problem: some users that are connected to my platform simply don't return the instagram_business_account when I'm requesting /me/accounts.
My request is to https://graph.facebook.com/v10.0/me/accounts with the fields id,name,instagram_business_account{id,biography,ig_id,followers_count,follows_count,media_count,name,profile_picture_url,username,website}.
Here's a sample result where both should return the instagram_business_account, because both are connected to Facebook as a Business Account:
{
"data": [
{
"id": "xxxx",
"name": "xxxxx"
},
{
"id": "xxxxx",
"name": "xxxx",
"instagram_business_account": {
"id": "xxxx",
"biography": "xxxx",
"ig_id": 00000,
"followers_count": 0000,
"follows_count": 0000,
"media_count": 0000,
"name": "xxx",
"profile_picture_url": "xxxx",
"username": "xxxx"
}
}
],
"paging": {
"cursors": {
"before": "xxxx",
"after": "xxxx"
}
}
}
Does anybody have any idea what is the problem happening here?
I figured out the problem. This is a Facebook problem, there's nothing we can do. Instagram is connected on Facebook through instagram_business_account. If this value doesn't exist, that means the account is not connected correctly. The user should reconnect the page https://www.facebook.com/{id}/settings/?tab=instagram_management.
The id value is the one from query result. The second alternative is go to Instagram, go to the profile, click on "Edit Profile" and in "Page", just connect to Facebook again.
With that you will be able to get the correct result.

Is there any Google OAuth2.0 Scope present which can tell me when the user access his account last time

I know google provides lot of apis/scopes which we can use to manage google account (similar to this https://developers.google.com/gmail/api/reference/rest?apix=true). I am looking for an scope which can tell me when did user last accessed his/her account. Accessing account means checking email, playing YouTube video, anything.
You can review the login api, using this API you can verify the last time of a sucessfull login for a Workspace account.
A sample output were the time of the loggin is visible :
{
"kind": "admin#reports#activities",
"etag": "\"REDACTED\"",
"items": [
{
"kind": "admin#reports#activity",
"id": {
"time": "2021-05-28T19:30:23.868Z",
"uniqueQualifier": "REDACTED",
"applicationName": "login",
"customerId": REDACTED"
},
"etag": "REDACTED"",
"actor": {
"email": "user#domain.com",
"profileId": "11111111111111111111"
},
Please note that this report will log each time a user logs in with google, however if the user already has an active session and access to a google service this action will not be logged.

How can we get the phone number with Google OAuth API and facebook API used for social login?

How can we get the phone number with Google OAuth API login.
I am using scopes as
'scope' : 'https://mail.google.com https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.login '
and the request is as
var request = gapi.client.plus.people.get({'userId': 'me'});
Is there any scope we can use to get it.
I am getting response as with no sight of phone number :
{
"kind": "plus#person",
"etag": "\"vPymIyv1bT9LfmoUujkgN2yLMK0\"",
"gender": "male",
"emails": [
{
"value": "XXX#gmail.com",
"type": "account"
}
],
"urls": [
{
"value": "http://picasaweb.google.com/XXX",
"type": "otherProfile",
"label": "Picasa Web Albums"
}
],
"objectType": "person",
"id": "4354354334435465",
"displayName": "XXXXX YYYY",
"name": {
"familyName": "XXX",
"givenName": "YYYYY"
},
"url": "https://plus.google.com/1100335464643327",
"image": {
"url": "https://lh3.googleusercontent.com/-fgsdgfgU9-jU/AAAAAAAAAAI/AAAAAAAADkM/fgffdgdkM/photo.jpg?sz=50",
"isDefault": false
},
"isPlusUser": true,
"language": "en",
"ageRange": {
"min": 21
},
"circledByCount": 59,
"verified": false
}
if you want to get user phone numbers you have to have authorization from the user: see the following info page : https://developers.google.com/admin-sdk/directory/v1/guides/authorizing
ask the user for this scope of authorization :
https://www.googleapis.com/auth/admin.directory.user.readonly
after you have authorization from user run the folowing request :
GET https://www.googleapis.com/admin/directory/v1/users/userKey
the response will be a JSON response formatted as followed:
https://developers.google.com/admin-sdk/directory/v1/reference/users#resource
one of the attributes is phone list.
hope it helps.
You can use google's people API to get the user's phone numbers.
To explore more you can try yourself.
Steps to explore:
Visit this link.
Select https://www.googleapis.com/auth/user.phonenumbers.read permission in People API v1 section
Click on Authorize API
Choose the account to log in
Grant permission
Click Exchange authorization code for tokens
Enter https://people.googleapis.com/v1/people/138262720636785143353?personFields=phoneNumbers,emailAddresses link, make sure you replace the UID
Click on send request to see the response

get profile picture from google plus

I have used google app engine with django application. I have been using the user api from google to login in my website and also getting the current user email address from that, but i have to get profile picture which is uploded on the google plus account.
I am getting their profile picture using,
<img src="https://plus.google.com/s2/photos/profile/<user_id>?sz=100" width="100" height="100">
in google api.
User class also provides user_id but I cannot get their profile picture using that user_id.
<user_id> and user_id of user class of Google API is different.
How to get the profile picture in my application?
The way to do it is to use the google+ api here: https://developers.google.com/apis-explorer/#p/plus/v1/plus.people.get?userId=me&_h=2&
This is the request to pull the image for the currently authenticated user.
GET https://www.googleapis.com/plus/v1/people/me?key={YOUR_API_KEY}
You'll get a json response like this and it's really easy to parse that and pull out the image->url value to display.
{
"kind": "plus#person",
"etag": "\"XxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx\"",
"gender": "male",
"emails": [
{
"value": "jbrahy#XxXxXxXx.com",
"type": "account"
}
],
"objectType": "person",
"id": "XxXxXxXxXxXxXxXxXxXxXxXx",
"displayName": "John Brahy",
"name": {
"familyName": "Brahy",
"givenName": "John"
},
"url": "https://plus.google.com/XxXxXxXxXxXxXxXxXxXxXxXx",
"image": {
"url": "https://lh3.googleusercontent.com/XxXxXxXx/XxXxXxXx/XxXxXxXx/XxXxXxXx/photo.jpg?sz=50"
},
"isPlusUser": true,
"language": "en",
"circledByCount": 2,
"verified": false,
"cover": {
"layout": "banner",
"coverPhoto": {
"url": "https://lh5.googleusercontent.com/XxXxXxXx/XxXxXxXx/XxXxXxXx/XxXxXxXx/XxXxXxXx/Green%2BGrass.jpg",
"height": 240,
"width": 420
},
"coverInfo": {
"topImageOffset": 0,
"leftImageOffset": 0
}
},
"domain": "XxXxXxXx-x.com"
}
If you are asking the about the ids...
My GoogleID according to user_id() is xxx8005350796570706xx and my Google Plus profile ID is 102445631084043565507 which are totally different
You need to ask the user for his G+ profile or authenticate him via oAth2.0 to get permissions to read his profile.
Also if you have his email address you could use GAvatar.

Facebook graph API obtain a specific users's pictures from that same user

I'm working on an Android application and I'm trying to obtain contact pictures from friends. I'm still testing the graph request on the Facebook Graph API Explorer linkhere I'm going to use afterwards in the code, and I've hit a snag...
After generating an Access Token, and validating it allows me access to the correct fields I'm interested, I'm trying to filter the information I'm obtaining from Facebook.
Using the Facebook Graph API Explorer I'm performing the following request:
< USER_ID>?fields=id,first_name,last_name,location,picture,birthday,photos.limit(3).fields(id,picture,source,from)
I obtain, as expected:
{
"id": "<USER_ID>",
"first_name": "<FIRST>",
"last_name": "<LAST>",
"photos": {
"data": [
{
"id": "<PICTURE1>",
"source": "<PIC1.jpg>",
"from": {
"name": "<OTHER_USER1>",
"id": "<OTHER_USER1_ID>"
},
"created_time": "2013-08-17T11:39:19+0000"
},
{
"id": "<PICTURE2>",
"source": "<PIC2.jpg>",
"from": {
"name": "<OTHER_USER2>",
"id": "<OTHER_USER2_ID>"
},
"created_time": "2013-08-04T14:27:07+0000"
},
{
**"id": "<PICTURE3>"**,
"source": "<PIC3.jpg>",
"from": {
"name": "<USER>",
**"id": "<USER_ID>"**
},
"created_time": "2013-08-03T17:35:20+0000"
}
],
"paging": {
"previous": "<LINK1>",
"next": "<LINK2>"
}
},
"picture": {
"data": {
"url": "<PIC>",
"is_silhouette": false
}
}
}
What I would like is to only obtain the pictures from ... like the third picture or others, is this possible using the graph api?
Thanks for the help.
Marc
PS:
I've tried adding in the end something like &photos.data.from.id=< USER_ID>
but I till get the same data set in response.
I would like to avoid requesting more pictures and filter it programmatically, because You never know how many pictures are associated with a user that where not submitted by that user.
Not possible with the Graph API, but you can use FQL, to query for the photos of the user (not those in which he's tagged in) -
SELECT pid,src FROM photo WHERE owner = me()
Check FQL - Photo to include the required fields in the result.