繁体   English   中英

从谷歌共享驱动器下载文件

[英]Download files from the google shared drive

我想下载文件 - Sarcasm_Headlines_Dataset.json 和 glove.6B.300d.txt 从https://drive.google.com/drive/folders/1s37-DVvRWfOcv59ojc6Dn我的驱动器中我可以读入 Google collab.M

在google collab中,我尝试了以下方法:

import urllib.request
urllib.request.urlretrieve('https://drive.google.com/drive/folders/1s37-DVvRWfOcv59ojc6DnwHzPFkA6e8M', 'Sarcasm_Headlines_Dataset')
os.listdir() 

import pandas as pd
url = 'https://drive.google.com/drive/folders/1s37-DVvRWfOcv59ojc6DnwHzPFkA6e8M'
df = pd.read_json(url, orient='columns')

https://developers.google.com/drive/api/v3/quickstart/python - a) 我下载了用于桌面应用程序的客户端 API,以便将项目快速启动到我的本地驱动器中。 (凭证.json)。 b) 安装了 Google 客户端库 c) 当我运行 python quickstart.py 时,它说请访问此 URL 以授权此应用程序。 我参观了 url 并得到了

Error 400: redirect_uri_mismatch; does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/${your_client_id}?project=${your_project_number}

我去了 API 控制台,在 web 浏览器中获取了客户端 ID 和客户端密码。 再次重新运行 python quickstart.py 并得到相同的错误。

我相信我需要在 google collab 中运行以下代码:

request = service.files().get_media(fileId=file_id)
fh = io.FileIO(location + filename, 'wb')
downloader = MediaIoBaseDownload(fh, request, 1024 * 1024 * 1024)

我不能file_id。 请帮忙。

我希望 json 在 google collab 中运行 LSTM 代码。

你甚至不需要 API 哈哈

您可以通过右键单击文件并单击查看链接来获取文件 ID,从那里复制链接并删除除此 ID 之外的所有内容https://drive.google.com/file/d/**1LWVnOp1rw4g9SYSwuf8IPAHBoOnWOTF0**/查看?usp=共享

import requests
# Getting the File id
file1_id = '1-JzJ5MIVuKG6Vhg5tA1ATh185WmXUqWL'
file2_id = '1LWVnOp1rw4g9SYswuf8IPAHBoOnWOTF0'

# Requesting data
file1 = requests.get('https://drive.google.com/uc?export=download&confirm=9_s_&id=' + file1_id)
file2 = requests.get('https://drive.google.com/uc?export=download&confirm=9_s_&id=' + file2_id)

# Saving data
open('glove.6B.300d.txt', 'wb').write(file1.content)
open('Sarcasm_Headlines_Dataset.json', 'wb').write(file2.content)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM