Google drive api 为什么会出现错误;“需要权限类型字段”;关于googledriveapi
我正在尝试更改某些文件的权限,google drive返回一个 错误Google drive api 为什么会出现错误;“需要权限类型字段”;关于googledriveapi,google-drive-api,Google Drive Api,我正在尝试更改某些文件的权限,google drive返回一个 错误 permission type field required 然而,我提供的类型。所以请有人告诉我我错过了什么 注意:hauth是oauth2授权的http对象 #%% find files and list [This works fine] q="title='testpop'" u="https://www.googleapis.com/drive/v2/files" u=u+"?"+urlencode(dict(q=
permission type field required
然而,我提供的类型。所以请有人告诉我我错过了什么
注意:hauth是oauth2授权的http对象
#%% find files and list [This works fine]
q="title='testpop'"
u="https://www.googleapis.com/drive/v2/files"
u=u+"?"+urlencode(dict(q=q))
resp, content = hauth.request(u, "GET")
files = json.loads(content.decode("utf-8"))
for f in files["items"]:
print(f["title"], f["id"])
#%% make public [this returns error "permission type field required"]
for f in files["items"]:
u="https://www.googleapis.com/drive/v2/files/{fileId}/permissions" \
.format(fileId=f["id"])
body = json.dumps(dict(role="reader", type="anyone"))
headers=dict(content_length=len(body))
resp, content = hauth.request(u, "POST", headers=headers, body=body)
break
以下是返回的内容:
b'{\n "error": {\n "errors": [\n {\n "domain": "global",\n "reason": "required",\n "message": "Permission type field required",\n "locationType": "other",\n "location": "permission.type"\n }\n ],\n "code": 400,\n "message": "Permission type field required"\n }\n}\n'
我认为body应该是body=dict(role=“reader”,type=“anywhere”)。实际上body必须是一个字符串。但是,您提示我尝试使用json头,它可以使用头={“content type”:“application/json”}。谢谢。