Drive API children.list q parameter broken - google-drive-api

The query string in try it section does not work 12 hours ago.
My query string is mimeType = 'application/vnd.google-apps.folder'
Anyway not work with any query.
https://developers.google.com/drive/v2/reference/children/list
Please tellme why??

I'm having the same issue:
child.Q = "mimeType = 'application/vnd.google-apps.folder' and title contains 'SomeDocuments'"
Dim cl As ChildList = child.Fetch
it returns all the documents like there was no filter
Maybe something change on Google Drive API?
Update
I can't find anything from Google, I wrote a feedback in the child list page.
The only workaround so far is instead of using the children.list use the file.list method and in the q section add the - 'folderid' in parents - search term to emulate searching on childrens of the parent folder.
The drawback is it will only search for document that has folderid as parent, not sub-folders like children.list method do.
Update 2
Looks like Google fixed it!
Happy coding.

Related

Get image_id of all images in google drive folder

Good afternoon. I am currently working on a project and I need to use python to get all the image_ids of the images in a folder. I have tried to use
query = f"parents = '{folder_id}'"
files = service.files().list(q=query).execute()
but for some reason this returns an id which is different to the real image id you can find in drive. Any tips?
Answer:
Your query parameter is malformed.
More Information:
The q parameter needs to be rewritten as:
'folderId' in parents and mimeType='image/jpeg'
where folderId is the ID of the folder in which you wish to search.
The q parameter allows you to specify properties of the files you are trying to list - so you're saying here "List all files that have a mimetype of image/jpeg, where folderId is contained in its list of parents."
Im suprised that works at all since parents use in not =
Example
To return all the files in the folder.
parents in '{folder_id}'
This would give you all the jpeg files on your drive
mimeType='image/jpeg'
You can put them both together using and
parents in 'root' and mimeType='image/jpeg'

Updating Google Sheet with WooCommerce Order

I need to be able to automatically update a google sheet file every time an order is placed through WooCommerce.
I've found the solution below, but using this each individual item ordered is listed as a new row. I'd like the order to be grouped under the order number and the item quantities separated into appropriate columns instead.
https://www.tychesoftwares.com/export-woocommerce-orders-to-google-sheets-in-realtime/
Below is a Google Sheet we are manually updating at present to show you what i mean.
Example
Is there a way to send the WooCommerce orders directly through to Google Sheets in this format?
Thanks so much in advance for any advice!
Yes it looks possible.
I know nothing about WooCommerce, but I believe you can sort out the received data in any way you want.
Look, the last line in their script appends the received data as a new row:
sheet.appendRow([timestamp,order_number,order_created,order_status]);
As far as I can see, the data contains the four elements:
timestamp
order_number
order_created
orders_status
Instead, you can put these elements into any cell on your table. Something like this, for example:
var ss = Spreadsheet.GetActiveSheet();
ss.getRange('A10').setValue(timestamp); // timestamp goes to A10
ss.getRange('B20').setValue(order_number); // order_number goes to B20
ss.getRange('C30').setValue(order_created + order_status); // created + status go to C30
The same way you can add any of these elements to some existing value in some cell, etc. For example:
var old_value = ss.getRange('A2').getValue(); // get value from the cell A2
var new_value = old_value + order_number; // add with order_number
ss.getRange('A2').setValue(new_value); // put the sum back into the cell A2
The main problem is up to you. You have to figure out:
what exactly the elements you're receiving (number, names)
how exactly you want to sort them out (what to add to what... what to put where... etc)
I can't understand it from the example picture.
Here is some reference documentation on Apps Script:
Main Page - Introducing Apps Script.
Sheets Guide - Introduction to Sheets with Apps Script.
Sheets Reference - Where you will find all the details of everything you can do with Sheets in Apps Script.
Remove Duplicate Rows - A good small tutorial that will teach you the basics of Sheets and Ranges and how to manipulate them.
To export all my WooCommerce orders on a scheduled basis, I used a ready-made solution.
I used a WooCommerce API and JSON client. It worked smoothly: I got the WooCommerce API, and the JSON client was implemented in the tool already.
You just need to choose endpoint in the JSON client to get the required data. I exported all orders once a month, so I used the base URL http:// mydomain /wp-json/wc/v3/orders and my endpoint was orders.
You can check this article to understand better how it works for your purpose.
And here is WooCommerce API documentation.
I assume that setting up an export through the Apps Script is more flexible (and based on the answer above, it's working indeed), but I'm not a code guy. So I searched for an easier solution, and the API + JSON client helped.
Hope you'll find it helpful.
I would like to suggest using WooCommerce Google Sheet Plugin

Retrieve Google Spreadsheet Worksheet JSON

I try to receive the JSON of a Google Spreadsheet Worksheet. It worked till some days ago. For the default worksheet it still works, but not for all other worksheets.
This is the working URL for the default worksheet: https://spreadsheets.google.com/feeds/list/1caRqAA1TyBoZ0eVZvvKheEBh9SGRmQII4qih9urY70k/od6/public/full?alt=json
And this is the URL for the worksheet that stopped working: https://spreadsheets.google.com/feeds/list/1caRqAA1TyBoZ0eVZvvKheEBh9SGRmQII4qih9urY70k/1416241220/public/full?alt=json
The error message is Invalid query parameter value for grid_id.
Only difference is the worksheet parameter (od6 vs 1416241220).
Any ideas on why that error suddenly occurs?
ChrisPeterson's note:
You can use worksheet position number (1 for the first/default worksheet, 2 for the second worksheet).
Original answer
I came across the same issue and I managed to find my way out.
It seems that they recently changed the id for each worksheet.
You can find the new ID at the following
https://spreadsheets.google.com/feeds/worksheets/YOUR_SPREADSHEET_ID/private/full
I got something like o3laxt8 between <id> tags
Ps: od6 anddefault values will always work and redirect to the first worksheet of your document.
Joe Germuska' note:
od6 doesn't work anymore
Seems to work again.
I'd like to share a concrete example because I find there are enough confusing instructions out there including the accepted answer and worksheet IDs and where to put them not being obvious.
Here's a document I published and anyone with the link can view:
https://docs.google.com/spreadsheets/d/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/edit?usp=sharing
The document has to be published correctly. There are two Publish buttons and the first one doesn't work for this task. Use the second.
The document KEY is important. Obtain the KEY from between the /d/ and the /edit in the url. In my example, the key is 1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c.
Second, use the following URL style, replacing KEY with your own:
https://spreadsheets.google.com/feeds/list/KEY/od6/public/values?alt=json
My example url links directly to published json:
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/od6/public/values?alt=json
Finally, if the worksheet has multiple sheets (or tabs), replace od6 in the url with a number. My example has two tabs, so there are two urls corresponding to either tab. I simply replace od6 with 1 and 2 depending on the order of the sheets:
Tab 1:
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/1/public/values?alt=json
Tab 2:
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/2/public/values?alt=json
In the event of a worksheet where the tabs are reordered frequently, it is possible to get the ID of a given sheet and use that instead of ordered numbers. I first learned of this approach from this post or this post:
In brief, you would reform a private URL with your KEY:
https://spreadsheets.google.com/feeds/worksheets/KEY/private/full
This only works on a browser where you are logged into Google Drive on an account with permissions.
Next, you have to sift through XML to find your sheet IDs:
Replace the previous 1 and 2 with the IDs, for example:
Tab 1 (first worksheet id in a new google sheet is always od6 by default, no matter order of tabs):
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/od6/public/values?alt=json
Tab 2:
https://spreadsheets.google.com/feeds/list/1QDWpycJJFA-UAiSPIv-icJ4UZhbEmuN8wxxag83SE1c/ope57yg/public/values?alt=json
You can find the new ID at the following
https://spreadsheets.google.com/feeds/worksheets/YOUR_SPREADSHEET_ID/private/full

Drive API to get Documents, Spreadsheets,Presentations alone?

I want to get documents/spreadsheets/presentations alone from drive.I used search query q parameter to get documents based on mimeType, but using this I can able to get only one particular mimetype files.Drive supports two mimetypes for spreadsheets
1.application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
2.application/x-vnd.oasis.opendocument.spreadsheet
There is no or operator to form a query.Can anyone help me to get a solution for this?
There is an OR operator. Use mimeType = 'application/vnd.google-apps.spreadsheet' or mimeType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' to query your files.

How to retrieve the titles of a folder's children in Google Drive?

It appears that listing the children of a folder doesn't actually return the titles of said children according to the Google Drive documentation.
Do I have to query using the id of every single child to determine the name of the file/folder?
Thanks!
EDIT:
Just occurred to me, is the way around this to do a search where the parent id is equal to the folder id I want to see the contents of?
You are absolutely correct, listing the children of a folder only gives you their ids, so you have to send other queries to retrieve titles and the other metadata. I agree this is not optimal and we are considering making some changes here to improve the developer experience.
In the meanwhile, I'd recommend adopting your workaround and search for those files whose parent is the folder you want to see the contents of.
If anyone is still looking at how to get the title of a folders children assuming you already have the children(fileId) id's
function getFileProps(fileId, callback) {
var request = gapi.client.drive.files.get({
'fileId': fileId
});
request.execute(function (resp) {
callback(resp);
});
}
You should use query params for files.list() method for getting that results,
In my example in Python it was:
service.files().list(maxResults=1000, q="'{0}' in parents".format(root_id)).execute()
all query params you could see this link: