I'm testing out Google Drive 'Changes' API and have some questions.
Expectation:
I've folder tree structure under 'My Drive' with files in them. I would like to call the Changes:list API to detect if items have been added/edited/deleted within that specific folder id.
APIs Explorer tried: https://developers.google.com/drive/v2/reference/changes/list
Questions:
I don't see any option to pass a specific folder id to this API for getting the 'largestChangeId'. Looks like this api doesn't support the parm 'q'? Is it possible?
As an alternate solution, thought of storing the 'modifiedDate' attribute for that folder and use it for comparing next time. But, it's not getting updated when items are updated within that folder. Should it not work like in windows where folder modified date gets updated when its contents gets updated?
Would like to hear if it's possible to detect changes at folder level.
Thanks
[EDIT]
Solution that worked:
Use Files:list to list all.
selected fields: items/id,items/modifiedDate,items/parents/id,items/title
Get starting folder id ( e.g for 'MyRootFolder' using Title search)
Traverse through the sub-tree structure (linking parents:id and file Id) using recursive array search and get max modifiedDate and total file counts.
Store max modifiedDate and file counts in the app storage.
For subsequent calls, compare the new max modifiedDate with the stored and also compare total file counts with the stored. If either one doesn't match, then contents within 'MyRootFolder' has been updated.
This is not currently possible directly with the API -- sorry!
I think the best current solution would be to use the regular changes feed and filter results in your code to ones with the correct parents set.
drive.changes.list google drive API now allows users to pass the "startChangeId" parameter.
Im using the value I get for "largestChangeId" from the previous API result, So I can incrementally build the changes done by the user, avoiding the need to rebuild the entire tree.
how ever I'm surprised to see why they don't support the "includeDeleted" parameter together with "startChangeId" parameter.
Related
When I use https://www.googleapis.com/upload/drive/v3/files without uploadType=resumable I receive back a JSON containing the file id. So this is ideal for creating folders.
If I want to add a file > 5MB I have to use resumable and I receive a upload URL for use with PUT.
Presently I am performing a list of the folder by specifying the file name and folder id and then pick the one with the latest date.
The documentation refers to querying the location URL but I can not find any examples to whether this returns the file id.
Can anybody explain how to get the file id easily.
Regards Conwyn
When you use the Google Drive API to create a file > 5M you have to use POST with uploadType=resumable. This returns a URL which you use with PUT. When the PUT completes it returns the file metadata [[:]] from which you can determine the file id ["id"].
I have suggested a documentation change to Google.
Regards Conwyn
I have a google drive directory with many files. In theory I could access them and cross-link them via
https://developers.google.com/drive/v2/reference/files/watch
or just using an URL with this identifier. The key issue is, how can I export the identifiers for the files in a google directory, doing this manually is not an option.
source:
https://developers.google.com/drive/v2/reference/
Export? I'm not sure I entirely understand what you mean by that, but I'm guessing you want a list of all the file IDs in a certain directory.
This is a simple case of using the files.list request. For 'q' you would want to do '<folderID>' in parents and for fields you would do items/id,nextPageToken (for efficiency). items/id gets you the file ID and nextPageToken is used to resend the list request to get the next set of IDs in the event it requires more than 1 page of results.
So, as an example, let's assume the folder you want is your root folder 'My Drive'. In that case, the following would be the query:
GET https://www.googleapis.com/drive/v2/files?q='root'+in+parents&fields=items%2Fid%2CnextPageToken&key={YOUR_API_KEY}
and if nextPageToken comes back with something, you would subsequently do:
GET https://www.googleapis.com/drive/v2/files?pageToken={YOUR_PAGE_TOKEN}&q='root'+in+parents&fields=items%2Fid%2CnextPageToken&key={YOUR_API_KEY}
Box api is implemented to be RESTful. and most supported methods are based on ids, folder_id or file_id.
As a very beginning start point, a root folder id, 0, stands for the root directory /All Files/.
from there (fold_id = 0), I can loop through all sub folders and find folder id for certain target folder.
or I can send search request to "https://api.box.com/2.0/search?query=target_folder_name", and process the response to locate target folder.
The former approach may need multiple list-folder-item requests, and the latter approach might be slow because the search is not just for folder/file name but also for other attributes of folder/file and even file content.
I am wondering if there is an easy way to find folder id for certain folder with a given path, such as "/All Files/MyFolder_A/Project_11".
Thank you very much for any help.
To the best of my knowledge, walking the folder tree (as you've suggested) is still the fastest way to get the ID of a particular file/folder. (See also this question: Get file ID of a given path.)
I am trying to utilize Google Drive as repository for many different types of documents. I have those documents arranged in several different folders.
When I perform a search it seems to search my entire Google Drive account for matching results regardless of the fact that I am currently within a specific folder.
This poses a problem for me as I want to be able to refine my searches to within a given grouping of documents.
If I am searching for documents related to my work, for instance, I don't want documents showing up in my search that are personal, or in my personal directories.
Is there a way to refine my search to only show documents within a specified folder and it's subfolders? I know I can refine the search based on file type and ownership, but that doesn't work for me.
Thanks in advance.
Using the Google Drive SDK, you can perform a search query for <folder_id> in parents.
The code I have included allows me to search the body of files within a specific folder. I am using it to search scanned documents and will have it move the file to another folder based on search criteria I specify.
The great thing about this is that it will search the body of the document and return all documents that meet your search criteria. As you can see I can also specify a date range and you can use other operators to define your search. https://developers.google.com/drive/web/search-parameters.
This was a great find for me and I hope it can help some others.
function searchFolder(){
var parent = DriveApp.getFolderById(‘*******************’); // folder Id
var search = 'modifiedDate >"2014-08-01" and modifiedDate < "2014-12-31" and fullText contains "PUT SEARCH TEXT HERE"';
var specificFolder = parent.searchFiles(search);
while (specificFolder.hasNext()) {
var file = specificFolder.next();
Logger.log(file.getName());
Logger.log(file.getId());
}
}
As far as I know you'd have to do this for each subfolder, but the API (and my app) will search by folder.
I wrote an app that uses the API to search by folder. It is a bit slow so be patient when it is loading.
https://script.google.com/macros/s/AKfycby6G32K-vKCiLmoKvMtG64cYPHEREEx1PY5IoYrEYaR6WAfbXs/exec
// -----------------
var sr = DocsList.getFolder("temp_scripts").find("var");
var i = 0;
for(i=0;i<sr.length;i++)
{
var r = sr[i];
Logger.log('name='+r.getName());
Logger.log('parent=' +r.getParents()[0].getName() );
Logger.log('---');
}
// -----------------
I found a sort of workaround using the description field.
In my particular case, all the files created in the folder i want to search are created programmatically by my own script, but is quite simple to write a script to (re)define the description field into all the files in a specific folder using .setDescription(DESCRIPTION). Once this is done...
The good news is that the standard search in google drive give results based on the description field, including the value set on it into the search field (plus any data you want to find into those files) you will get the results you need.
Of course you need to scarify the description field (or, at least, overcrowd it;-)
As, I think all of you, I'm still waiting for the folder keyword in the standard serch field.
I implemented the function in this Chrome Extension.
https://chrome.google.com/webstore/detail/advanced-drive-search/chomjcpadndbjgkanbaakmjehdoighab
You can check the code here
https://github.com/kissrobber/advanced_google_drive_search_chrome_extension
What that do is
get all the folders
build a query with the folder_id and the descendant folder_ids. Like this (<folder_id> in parents or <folder_id> in parents or ....)
If you have concern with the performance, try the Chrome extension.
There is another workaround that do NOT require any third party app or extension.
Remove your folder (In which you wanna search something)
Search with is:trashed filter. For example: is:trashed query_string
Restore your folder back
The Google Checkout orders page allows you to download the orders data as CSV. There is a checkbox that allows you to specify that the CSV should include extra data (buyer's name and address, product details).
The Google Checkout Order Report API provides a way to get CSV order data programmatically. However, it doesn't seem to be possible to get the data in the extended format. Am I missing something? Is there some way to specify that you want the full data?
The default data is pretty uninformative.
Well it's not documented, but after a bit of sniffing around and experimenting I discovered that the <order-list-request> API method accepts another nested parameter tag, <column-style>, and that this should be set to EXPANDED.
So a request for the full CSV looks like this:
<order-list-request xmlns="http://checkout.google.com/schema/2"
start-date="2010-08-01T00:00:00"
end-date="2010-08-31T23:59:59">
<date-time-zone>Europe/London</date-time-zone>
<column-style>EXPANDED</column-style>
</order-list-request>