Delete files from Google drive using python through google drive api - python-3.x

I am trying to delete files from my google-drive using google drive apis for python.
I am able to retrieve the list of parents/children for a particular folder but when I try to delete one of the retrieved parent of the folder it gives me below error.
"https://www.googleapis.com/drive/v2/files/1j1sZ-0OAiTE9836bhTTpkUf3i4AFAvmG/parents/0AO-cNLqoD0BFUk9PVA? returned "Insufficient Permission">"
I have defined "https://www.googleapis.com/auth/drive" as my scope.
The same file got deleted when I tried "try this API" option from
developer-google.com but it does not work from my python code.
Is there anything else in the configuration that I need for deleting the files.
Thanks.

Related

How to get the file link from a SharePoint/OneDrive Sync location

I am currently using Registry Editor to obtain the cloud OneDrive URL of a local OneDrive folder, through:
HKEY_CURRENT_USER\SOFTWARE\SyncEngines\Providers\OneDrive\ -> UrlNameSpace.
However, for shared folders I cannot seem to obtain the correct path based on the UrlNameSpace property. For example the following below returns:
C: Drive path (MountPoint) - C:\Users\nathan.hurley\MyCompany\John Smith - ShareFolder
(UrlNameSpace) - https://mycompany.sharepoint.com/personal/john_smith_mycompany_com/Documents
Following the example above, if I'm trying to get the cloud OneDrive URL for:
C:\Users\nathan.hurley\MyCompany\John Smith - ShareFolder\Test
Replacing the C: Drive path with the UrlNameSpace will produce the following path:
https://mycompany.sharepoint.com/personal/john_smith_mycompany_com/Documents/Test.
The problem with this online link, is that it doesn't obtain the root synced folder and opening the link will lead to a 404 page error. The correct URL should be the following:
https://mycompany.sharepoint.com/personal/john_smith_mycompany_com/Documents/ShareFolder/Test
Again, I've noticed this issue only occurs with shared folders and within the Registry Editor, these folders also include an additional property called IsFolderScope. Is there an efficient way to determine which folders are Shared Folders other than checking the IsFolderScope property? Also, are shared folders the only folders that include this property?
Reference: https://tdalon.blogspot.com/2020/12/get-url-from-sync.html

Correctly enter the site_ID using Graph SDK

Regarding this expression to create a folder:
POST /sites/{site-id}/drive/items/{parent-item-id}/children
What is the correct way to enter the {site-id} and the {parent-item-id}, to access a folder (eg:folder_1) in a site (eg: site1)in a domain (eg: mydomain)
I have tried:
POST /sites/mydomain/drive/items/site1/folder_1/children
POST /sites:/mydomain/site1:/drive/items/folder_1/children
and similar, with no success,
Can you help me please?
THanks for the help.
Follow your steps, but In the second step, you say:
"This is the sub folder named "2019" in default Documents library:"
With this, I can acess the shared documents folder inside the site. I don't want to acess that folder. I need to acess another folder that is in the site, but not inside the share documents folder.
Any clue?
Do a get request like this in Graph Explorer with this request:
https://graph.microsoft.com/v1.0/sites/<host>:<server relative url>
Example:
https://graph.microsoft.com/v1.0/sites/zheguo.sharepoint.com:/sites/dev
Then will return site Id
Update if you want to access other library folder in Graph, firstly get drive id with this endpoint:
https://graph.microsoft.com/v1.0/sites/{site-id}/drives
Then access the specific drive folder with this endpoint:
https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}
Then for "parent-item-id", it's the specific folder id in document library, you can get with this endpoint:
https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/items/root:
Example:
https://graph.microsoft.com/v1.0/sites/zheguo.sharepoint.com,91a47a59-db5e-4d17-a689-479ee8905533,274459c9-4c96-42bf-9b96-838ffa387aaa/drives/b!WXqkkV7bF02miUee6JBVM8lZRCeWTL9Cm5aDj_o4eqpLdqmLE2R7QosYOZt8Dyao/items/root:/
Then use the endpoint to create folder:
POST /sites/{site-id}/drives/{drive-id}/items/{parent-item-id}/children
Example:
https://graph.microsoft.com/v1.0/sites/zheguo.sharepoint.com,91a47a59-db5e-4d17-a689-479ee8905533,274459c9-4c96-42bf-9b96-838ffa387aaa/drive/items/01WU7SPCC4FNS6KOYTSJFK2MUFRITF5XQL/children
Reference:
Create a new folder in a drive

Google Cloud Natural Language Example

I have followed the getting started page closely.
https://cloud.google.com/natural-language/docs/reference/libraries#client-libraries-install-php
The example code has the following: $projectId = 'YOUR_PROJECT_ID';
I fill in my project id taken from the json file and the Google console--e.g. "$projectID = 'myproject-197218'" and I always get a fatal error with "Permission Denied."
I have set the env variable, run composer to install the library. And, I created the Google json file. I am running the example in PHP code.
I am running the code on my local server (xampp).
I figured out my problem. The Google Cloud json file was stored on my drive d:, so in the env variable I referenced it as 'GOOGLE_APPLICATION_CREDENTIALS= d:\xampp\htdocs\googapi\mproj.json', it did not work; when I moved it to the root of the c: drive and referenced it there (GOOGLE_APPLICATION_CREDENTIALS=c:proj.json), it worked fine.
Are you sure that the ID of your project is that one? I'm working in Google Cloud and I cannot see this project ID in our database, but if I type "my-project-197218" with a "-" between "my" and "project" I am able to find one project. please, to make sure that this is your correct project ID, run this command in your Google Cloud Shell to get the default project ID:
gcloud config list --format 'value(core.project)' 2>/dev/null

How to rename project with Google Apps Script API

Is there any way to rename Google Apps Script project using API? I can't find any appropriate method for this.
UPD: I want to change Project's name like
You can modify the project name of the container-bound script type using Drive API. In order to use this, please retrieve the project ID, retrieve access token and enable Drive API.
End point :
PATCH https://www.googleapis.com/drive/v3/files/### project ID ###
Request body :
{
"name": "### Modified name ###"
}
Note :
In Google Drive, the project name is the same to the filename of the project.
Unfortunately, in the current stage, the project ID cannot be retrieved from Spreadsheet. But by the recent update, the file ID of Spreadsheet got to be able to be retrieved from the project of the container-bound script type. I would like to expect that the project ID will be retrieved from Spreadsheet in the future.
Reference :
Files: update

Setting Metadata in Google Cloud Storage (Export from BigQuery)

I am trying to update the metadata (programatically, from Python) of several CSV/JSON files that are exported from BigQuery. The application that exports the data is the same with the one modifying the files (thus using the same server certificate). The export goes all well, that is until I try to use the objects.patch() method to set the metadata I want. The problem is that I keep getting the following error:
apiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/storage/v1/b/<bucket>/<file>?alt=json returned "Forbidden">
Obviously, this has something to do with bucket or file permissions, but I can't manage to get around it. How come if the same certificate is being used in writing files and updating file metadata, i'm unable to update it? The bucket is created with the same certificate.
If that's the exact URL you're using, it's a URL problem: you're missing the /o/ between the bucket name and the object name.

Resources