Skip to content

Instantly share code, notes, and snippets.

@yume-yu
Created October 13, 2019 07:59
Show Gist options
  • Save yume-yu/a5d7b1283c395aac66e7fc07638e6855 to your computer and use it in GitHub Desktop.
Save yume-yu/a5d7b1283c395aac66e7fc07638e6855 to your computer and use it in GitHub Desktop.
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