最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Google Drive API: Starred folder update does not reflect in Google Drive - Stack Overflow

programmeradmin1浏览0评论

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 = [";]

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:

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:

发布评论

评论列表(0)

  1. 暂无评论