muw
muw

Reputation: 385

Google Drive API: Starred folder update does not reflect in Google Drive

I am trying to update the starred value of a Google Drive folder using the Google Drive API but it is not reflecting in Google Drive.

The name is getting updated but the starred value is not getting updated. There is an old case here on Stackoverflow claiming that it takes a very long time, but I have been waiting for more than 15 minutes and nothing changes.

Can someone help me with this?

First I am using the following code to create a folder:

from googleapiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

from my_creds import GOOGLE_DRIVE_API_CREDS, PARENT_FOLDER_ID

SCOPES = ["https://www.googleapis.com/auth/drive"]

credential = ServiceAccountCredentials.from_json_keyfile_dict(
    GOOGLE_DRIVE_API_CREDS, SCOPES
)

service = build("drive", "v3", credentials=credential, cache_discovery=False)

file_metadata = {
    "name": "Folder name",
    "mimeType": "application/vnd.google-apps.folder",
    "parents": [PARENT_FOLDER_ID],
}

directory = service.files().create(body=file_metadata, fields="id").execute()

Then the folder looks like this in Google Drive:

enter image description here

After that, I am trying to update the folder name and starred value using the following code:

update_metadata = {"name": "New folder name", "starred": True}

updated_folder = (
    service.files()
    .update(fileId=directory["id"], body=update_metadata, fields="name, starred")
    .execute()
)

if I run the following code:

updated_file = (
    service.files().get(fileId=directory["id"], fields="name,starred").execute()
)
print(updated_file)

I get the following output:

{'name': 'New folder name', 'starred': True}

But the starred value is not getting updated in Google Drive: enter image description here

Upvotes: 0

Views: 37

Answers (0)

Related Questions