Get drive files stats (views/openings) | Google Drive API - google-apps-script

I've been searching the docs but I can't find anything.
The goal is to retrieve different stats from our files. Actually, we can retrieve almost everything we need, except for the document openings and document openings per user.
So here is the question: How can I retrieve document views of a drive document (a G Sheet to be more precise) ? Can I segment it by user ?
Thank you

I understand that your goals are the following one:
You want to retrieve document views
Of a particular document (and you know it's id)
Associated to a specific user
Please correct me if I get it wrong. If those are your goals, then you can use the Admin SDK as pointed out by Rubén in the comments. Now I am going to detail how you can make such a request easily.
You could use the method activities.list() to get a list with what you want. You only have to populate these four parameters:
Parameter
Value
Description
userKey
The user's email
Determine the user
applicationName
drive
Identifies the Google service
eventName
view
Designate the type of activity
filters
doc_id=={MY DOCUMENT ID HERE}
Filters by the document
That configuration will provide you with your desired data. Leave a comment below if you need help creating that request in your own environment.

Related

Check if an URL belongs to a resource within the same document domain

I'm developing a script that checks every link (URL) in a Presentations to meet the following criteria:
If the link follows to a document within the same domain of the Presentation that I'm currently editing then remove the link.
The question is, is there a property, or any method in GAPPS that allows me to check that information, because I've reviewed the whole API and I cannot find anything like that.
There is no direct way to get the domain that a file belongs to buy you might be able to get the Presentation owner by using getOwner ( a method of the Class File from the Drive Service) or the equivalent of the Drive Advanced Service.
Once you get the owner email address, then you could extract the domain by using JavaScript's global object methods like String.prototype.split, regular expressions, etc.
Related
Determine the owner of a Google Drive document with a service account
returning document owner for large list of Google Drive doc IDs

Get User's first and last name via Google API

Currently I am developing a Chrome-GMAIL extension which requires me to get the logged in user's first and last names. For experimentation, I have used the following goggle API (userinfo) and have successfully obtained the names I wanted:
https://www.googleapis.com/auth/userinfo.profile
However, using the userinfo APIs will cause a change in the OAuth2 scopes in my manifest. This change will in turn cause a permission-prompt to my existing users (if a domain wide delegation is not setup in place). Point being the idea of having more prompts in front of my user, or additional oauth scope is not really something I desire.
Currently our extensions use the following OAuth scopes and API :
Chrome's Identity API
Chrome's Storage API
GMAIL.modify
GMAIL.send
My question is, is it possible to get the first and last names using an API that is defined/allowed/provided for by any of the above scopes/permissions I listed? or is userinfo the only way to go?
Thank you very much.
Profile data like first name and last name is private data. You are corect that some Google apis give you access to some data that would normally require an extra scope. For email normally you would need to to request the email scope to get this back however the Gmail api does have an endpoint getprofile which will return the current users email address without you requesting the email scope.
However i am not aware of any apis that will give you access to the users first and last name without you requesting the profile or user.profile scope.
If you do decide to add the scope, I do recommend going though the people api rather then the userinfo endpoint as the data returned by the user info endpoint is not guaranteed to always return the name.

Export the join date for members in a group

Is it possible to export a member's join date to a google group? When you manually export a .csv from a group it gives information on the join date. However, in google app script, I don't see the option for this in the Groups Service. This is the information that is in the .csv:
Any help or resources would be appreciated!
Short answer:
No, you cannot do that programmatically.
Long answer:
Google Groups functionality is mainly handled by Directory API, in its Groups and Members resources. That's what the Apps Script Groups Service is using behind the scenes, and you could use its methods directly by enabling the Admin SDK Directory Service in your script (the APIs —and, as a result, the advanced services— usually have greater functionalities than the Apps Script built-in classes).
If you look at the properties of any of these resources (Groups and Members), you won't find anything close to a join date property, so it doesn't seem to be part of the open API, and can only be accessed through the UI.
The same can be said of Groups Settings API, which can be used to manage group settings: no join date can be found in its resources.
Because of this, you have no way to programmatically store and retrieve the group member's join dates.
Workaround (of a sort):
If you are adding members to a group programmatically, with the API method Members: insert, you could make your application store the date in which each member was added, and retrieve it later. This is not possible, though, if members are added through the UI.
Filing a Feature Request:
Since this resource does seem to exist already (it can be accessed through the UI), I'd suggest you to file a feature request in this Issue Tracker component to make this available to the API. If you do that, please make sure that you explain the usefulness of this functionality (explain how this could help you and, potentially, other users).
Reference:
Directory API: Groups
Directory API: Members
Directory API: Manage Groups

How to get the owner of file using Google Drive API

I am thinking of developing an application like this:
My application has a google-service-account
I let my users share their documents with my service account
While an user visits my application, he gets some reports based on the files he has shared.
For this, my application needs to uniquely identify the owner of the documents shared with it. I looked at the API but could not find how to do so. I found methods like File.getOwnerNames(), but they are plain strings containing the names, but not any unique key to identify the user.
Need help on how to achieve this. Thanks.
Sanjay
Use the permissions.list method and find the permission corresponding to the owner.

Retrieve Access Control List of Documents for Specific User on Google Docs?

I have a large website at www.mydomain.com. There are 1000 new documents per month and 100 new users per week lets say. I need to be able to programmatically do the following:
user goes to www.mydomain.com/documents
user sees list of all documents they have access to (not ALL of the docs)
I know you can retrieve an ACL for each document individually. But is there a way to retrieve an ACL for each "user", a list of all the documents they have access to, in one HTTP request? Something like this, but for Docs (and not just for document "owners"):
Retrieving only calendars that a user owns.
I'd love to know, because it seems like I'd have to parse 10,000 document "entry" tags, find the ACL, see if user is in ACL... That seems crazy.
What am I missing?
Thanks!
It looks like the API can provide you the desired list by reader or writer.