我可以毫无问题地下载公共文件。 作为我的管理员,我会列出谁可以下载私人文件。(谷歌硬盘的功能) 这是我的代码:https://stackoverflow.com/posts/39225272/revisions 我有oauth2client和google drive-凭据.json文件位于.credentials文件夹中。 在此文件(google驱动器凭据)中,“access\u token”和“refresh\u token”可用。 当我尝试下载私人文件时,google会返回带有请求的登录屏幕html文件。我需要自动通过。这不应该发生。你知道吗
这是我的密码:
SCOPES = 'https://www.googleapis.com/auth/drive'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'abc'
authInst = auth.auth(SCOPES, CLIENT_SECRET_FILE, APPLICATION_NAME)
credentials = authInst.getCredentials()
URL = "https://docs.google.com/uc?export=download"
session = requests.Session()
session2 = requests.Session()
toplamyari = int(int(toplamboyut) / 2)
if os.path.exists(yazp1):
sizefile = os.path.getsize(yazp1)
yazmaModu = 'ab'
bytearalik = 'bytes=' + str(sizefile) + '-' + str(toplamyari)
else:
bytearalik = 'bytes=0' + '-' + str(toplamyari)
if os.path.exists(yazp1[0:len(yazp1)-1]+"2"):
dosyaboy=os.path.getsize(str(yazp1[0:len(yazp1)-1])+'2')
self.temp2boyut=dosyaboy
bytearalik2 = 'bytes=' + str(toplamyari + 1 + dosyaboy) + '-' + str(toplamboyut)
else:
bytearalik2 = 'bytes=' + str(toplamyari+1) + '-' + str(toplamboyut)
arlik2=int(int(toplamboyut)-int(toplamyari))
accessToken = credentials.access_token
session.headers.update({'Range': bytearalik, 'Authorization':'Bearer " + accessToken})
#session2.headers.update({'Range': bytearalik2}) #don't worry about that, that's for download faster(download 2 part at same time)
response = session.get(URL, params={'id':link}, headers={'Authorization':'Bearer '+accessToken}, stream=True)
有了我说过的代码,我可以下载公共文件,但不能下载访问给定的私人文件。我想不是请求访问,idk。对不起英语。谢谢大家。你知道吗
固定 已更改URL。你知道吗
相关问题 更多 >
编程相关推荐