Sharing files in Google Drive using Python - python

There are plenty of resources involving sharing files in Google Drive but I can't find anything useful to Python and the references by Google aren't Python-specific.
I've saved an item ID into the variable selected_id. In this case, I want to make that file shareable by URL to anyone for reading.
service.permissions().create(body={"role":"reader", "type":"anyone"}, fileId=selected_id)
This is what I have so far but I don't think I formatted it correctly at all.
Like the title states, how would I share a file by ID on GDrive using Python? Thanks in advance.

Looks like you've got the correct format as per Permissions:Create
Perhaps you just need to add .execute() on the end?
service.permissions().create(body={"role":"reader", "type":"anyone"}, fileId=selected_id).execute()
Also is you're looking for examples using the Python API check out the following repository:
https://github.com/gsuitedevs/python-samples
I would image that you're code might look like something similar to this:
https://github.com/gsuitedevs/python-samples/blob/master/drive/driveapp/main.py#L57

Related

How to get a list of Folders and Files in Sharepoint

I have started to explore the Graph API, but Sharepoint is quite complicated and I am not sure how to proceed. I previously have worked with OneNote using this API successfully.
Purpose: There are thousands of folders/files and I need to go through the list in order to organize it in a better way. I am looking for a way to export this list into Excel/CSV using Python and Graph API
I want to dynamically get a list of all underlying Folders and files visible from this URL:
https://company1.sharepoint.com/teams/TEAM1/Shared Documents/Forms/AllItems.aspx?id=/teams/TEAMS_BI_BI-AVS/Shared Documents/Team Channel1/Folder_Name1&viewid=6fa603f8-82e2-477c-af68-8b3985cfa525
When I open this URL, I see that this folder is part of a private group called PRIVATE_GROUP1 (on the top left).
Looking at some sample API calls here:
GET /drives/{drive-id}/items/{item-id}/children -> Not sure what drive-id
GET /groups/{group-id}/drive/items/{item-id}/children -> I assume group-id refers to private group. Not sure how to get the ID
GET /sites/{site-id}/drive/items/{item-id}/children -> Assuming site-id is 'company1.sharepoint.com'?
For all above not sure what item-id refers to...
Thanks
refer below code. This might help you.
https://gist.github.com/keathmilligan/590a981cc629a8ea9b7c3bb64bfcb417

Using Tenor API in Python for printing gifs

So, I am trying to print out gifs by using Tenor API.
I want it to only print one gif link but it prints out everything any Idea how to fix this?
Thank you.
https://i.stack.imgur.com/xf084.png
Sadly, I can not tell you the exact problem you are having, I replicated your code and used the official API Docs here
From what I can tell, this is one GIF just in a lot of different formats.
You can filter them like so:
print(top_8gifs['weburl'])
or
print(top_8gifs['results'][0])
EDIT: Looking at your .png (please embed it as code in the future) this should work for you, if you want the url:
print(top_8gifs[0]['url'])
A Python dict you can select using the key (like gifs['weburl'])
A Python list you have to select by index so gifs[0]
Using these techniques you can gather the data you need from that output.

Im looking for a way to mass find/replace hyperlinks in a google drive file

Im currently performing a migration of data from Box to Google drive. Most of these files contain links that reference, and then take the user to, other files within the box drive.
However, when i do eventually migrate the files to google drive, the old links will break and become obsolete as the previous location in Box will no longer exist.
Writing a find/replace script that updates the strings wont work as although the string changes the URL_link attached to it stays the same, does anybody have any suggestions? I can't seem to find anything about this in the google API.
I had the idea of breaking the link, updating the string, and then making it a link again. But once again, i can't seem to find how to create a link from a string in the API.
Any help would be really appreciated, thanks
Solution / Workaround
You can automate this using the Google APIs. These are the following steps I would follow to achieve what you are aiming for here:
Migrate the files to Google Drive (this will convert your documents into Google Doc files that then you can access with the Gooogle Docs API. Do this by specifying the MIME type in the metadata when doing the migration. Here you can see how to specify this and upload using the Google Drive API.
Once you have all your desired files uploaded to Drive as docs, you will get their body and look for the links in order to replace them. You can access the links by accessing the body element inside the document element, for more information with regards to this check this link and explore the nested objects. Perform a find replace on the body to change the URL of the document.
If you have issues regarding the change of attached links as you mentioned in your question, check out this other Stack Overflow answer that addresses this problems.
Change the link by updating the document following the instructions stated in the above Stack Overflow Question and the documentation.
I hope this has helped you. Let me know if you need anything else or if you did not understood something. :)

How to retrieve wav file from API?

I am working on Python3.4.4
I tried to use a Merriam-Webster API, and here is an example link:
http://www.dictionaryapi.com/api/v1/references/collegiate/xml/purple?key=bf534d02-bf4e-49bc-b43f-37f68a0bf4fd
There is a file under the tag, you will see after you open the url.
And I am wondering that how can I retrieve that wav file......
Because it is kind of just a string to me......
Thank you very much!
Okay, I just sort it out.
Usually you need to look at the instructions for the API, I look it up on the official website and it tells you that how you are going to retrieve that. In this case you are going to another url, and then wala

What is the equivalent of BlobstoreLineInputReader for targeting Google Cloud Storage?

This is a python appengine question, mapreduce library 1.9.21 .
I have code writing lines to a blob in the local blobstore, then processing that using mapreduce BlobstoreLineInputReader.
Given that the files api is going away, I thought I'd retarget all my processing to cloud storage.
I would expect to find a class called GoogleCloudStorageLineInputReader, but there isn't anything like that. Is it hiding somewhere?
Is there something way I can use GoogleCloudStorageInputReader to read lines?
Another possibility is using GoogleCloudStorageRecordInputReader, but for that my input file needs to be in LevelDB format and I don't know how to create that except with a GoogleCloudStorageConsistentRecordOutputWriter, which I don't know how to use outside a mapreduce context. How might I do that?
Or am I doing this all wrong, is there some other possibility I've missed?
At first, I attempted thinkjson's CloudStorageLineInputReader but had no success.
Then I found this pull request...which led me to rbruyere's fork. Despite some linting issues (like the spelling on GoolgeCloudStorageLineInputReader), however at the bottom of the pull request it is mentioned that it works fine, and asks if the project needs to be taken over.
Hope that helps!

Categories

Resources