【问题标题】:Download files from the google shared drive从谷歌共享驱动器下载文件
【发布时间】:2021-04-05 01:52:15
【问题描述】:

我想将文件 - Sarcasm_Headlines_Dataset.json 和 glove.6B.300d.txt 从 https://drive.google.com/drive/folders/1s37-DVvRWfOcv59ojc6DnwHzPFkA6e8M 下载到我的驱动器中,以便我可以在 Google 协作中阅读。

在 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) 安装了谷歌客户端库 c) 当我运行 python quickstart.py 时,它说请访问此 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 代码。

【问题讨论】:

    标签: python google-apps-script google-drive-api google-oauth google-api-python-client


    【解决方案1】:

    你甚至不需要 API 哈哈

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

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-13
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-24
      • 1970-01-01
      相关资源
      最近更新 更多