简体   繁体   中英

Download files from the google shared drive

I wanted to download files - Sarcasm_Headlines_Dataset.json and glove.6B.300d.txt from https://drive.google.com/drive/folders/1s37-DVvRWfOcv59ojc6DnwHzPFkA6e8M into my drive so that I can read in Google collab.

In google collab, I tried the below:

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) I downloaded the client API for the desktop app for project quickstart into my local drive. (credentials.json). b) Installed the Google Client Library c) When I ran the python quickstart.py, it said Please visit this URL to authorize this application. I visited the url and got the

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}

I went to API console and got the Client ID and Client secret in the web browser. Again reran python quickstart.py and get the same error.

I believe I need to run the below code in google collab:

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

I couldn't file_id. Help please.

I wanted the json to run LSTM code in the google collab.

You dont even need a API lol

You can get the file id by right clicking the file and clicking view link, from there copy the link and remove everything thing except the id like this 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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