Created
October 13, 2019 07:59
-
-
Save yume-yu/a5d7b1283c395aac66e7fc07638e6855 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pprint import pprint | |
import connectgoogle as con | |
from apiclient.http import MediaFileUpload | |
gcon = con.ConnectGoogle() | |
file_metadata = { | |
"name": "img.jpg", | |
"mimetype": "image/jpeg", | |
"parents": ["1WM6yJVBgoqU9azui7d_EhGuFp5KDIjAN"], | |
} | |
media_body = MediaFileUpload("./sample.jpg", mimetype="image/jpeg") | |
file = ( | |
gcon.service.drive.files() | |
.create(body=file_metadata, media_body=media_body, fields="id") | |
.execute() | |
) | |
# file = gcon.service.drive.files().list().execute() | |
pprint(file) | |
fileid = file.get("id") | |
permissions = gcon.service.drive.permissions().list(fileId=fileid).execute() | |
pprint(permissions) | |
new_parmisson = {"role": "reader", "type": "anyone"} | |
changed_permission = ( | |
gcon.service.drive.permissions().create(fileId=fileid, body=new_parmisson).execute() | |
) | |
pprint(changed_permission) | |
print("https://drive.google.com/file/d/{}".format(fileid)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment