I'd like to use the Dropbox API (with access only to my own account) to generate a link to SomeFile.xlsx that I can put in an email to multiple Dropbox account holders, all of whom are presumed to have access to the file. I'd like for the same link, when clicked on, to talk to Dropbox to figure out where SomeFile.xlsx is on their local filesystem and open that up directly.
In other words, I do NOT want to link to the cloud copy of the file. I want to link to the clicker's locally-synced version of the file.
Does Dropbox have that service and does the API let me consume it? I haven't been able to discover the answer from the documentation yet.
No, Dropbox doesn't have an API like this.
Related
I'd like to make a function which converts Google Drive videos into VLC streamable links (e.g. vlc://https://WEBSITE.com/FILE_ID.mkv.
I've tried methods which were shared on stack overflow, such as modifying the Google Drive link to:
https://drive.google.com/uc?export=download&id=FILE_ID
All the methods I've tried seem to not work anymore. Any ideas?
I've figured out the answer.
Google Drives' API has a download feature, you just need to make a request to https://www.googleapis.com/drive/v3/files/FILE_ID?alt=media&key=API_KEY
Now this doesn't generate a direct file path ending with .mp4 or .mkv but VLC and PotPlayer are able to recognize this link like this:
potplayer://https://www.googleapis.com/drive/v3/files/FILE_ID?alt=media&key=API_KEY
vlc://https://www.googleapis.com/drive/v3/files/FILE_ID?alt=media&key=API_KEY
Edit: this doesn't work in development, Google prevents bots from making requests like that. To work around this you need to set a header in your request. e.g.
url = "https://www.googleapis.com/drive/v3/files/FILE_ID?alt=media&key=API_KEY"
r = requests.get(url, headers={"Authorization":"Bearer " + accessToken})
You get the accessToken from the Google Drive API
Just make the file public and copy your ID.
You can find it here: /file/d/YOUR ID/view?usp=sharing.
Copy your ID and paste it in this:
drive.google.com/uc?export=view&id=YOUR ID
Can I read a google spreadsheet which is open to people, but doesn't have a share option? There's a discussion here, but it's I need to have an authorization to click the share option.
Even copying by URL to my own Google spreadsheet may serve the purpose.
Update:
The idea was once I create a Google API, I should be able to create a .json file with a client email. In the share option, I'm supposed to provide the client email of .json file. You may see: Accessing Google Spreadsheet Data using Python.
This is the spreadsheet page where I'm not finding any Share option: https://docs.google.com/spreadsheets/d/e/2PACX-1vSc_2y5N0I67wDU38DjDh35IZSIS30rQf7_NYZhtYYGU1jJYT6_kDx4YpF-qw0LSlGsBYP8pqM_a1Pd/pubhtml#
Issue:
Publishing the contents of a spreadsheet to the web is not the same as making a spreadsheet public.
The URL you shared refers to spreadsheet contents that were published to the web following these steps. This published website is not the same as the original file where the data comes from, and so it doesn't have most of its functionalities, like a Share button (it doesn't make sense to have a Share button anyway, since this URL is already public).
Solution:
If you want to access the spreadsheet data using a Service Account, you would have to do one of the following (better to use method 1 if you have access to the spreadsheet):
Share the spreadsheet itself (not the published contents) with the Service Account, as explained in the link you referenced.
Use your application to fetch the website contents from the provided URL.
Reference:
Make Google Docs, Sheets, Slides & Forms public
Now I need to get the directory structure of the entire Google drive and download the files according to this directory structure
you can use the following request to get the list of children for any parent folder. Dont forget to add the key param in the request url
GET https://www.googleapis.com/drive/v2/files/{folderId}/children
For more information on this please refer to the google developers page about drive api.
I have a simple script set up for getting a file off my google drive account and updating it. I have no problems authenticating and getting access to the drive. The file is in the form of a google spreadsheet on the drive. Thus, when I have the pydrive file object, I get the URL of the file in csv format via google_file['exportLinks']['text/csv']. This has worked in the past, however today I tried this same method for a new file, and instead of getting the csv format of the data, I keep getting HTML. In addition, if I copy and paste the link from my google_file['exportLink']['text/csv'] and put it into a browser, the browser will begin to download the file in csv format as requested. I really have no idea what is going on, especially since this has worked in the past.
Here is basically what my code does:
drive = GoogleDrive(gauth)
drivefiles = drive.ListFile().GetList()
form_file = None
for f in drivefiles:
if f['title'] == formFileName:
form_file = f
break
output = requests.get(form_file['exportLinks']['text/csv'])
print output.text #this ends up being HTML, not text/csv
Has anyone else out there seen this problem before? Should I just try to delete and re-add the google spreadsheet file on the drive?
EDIT: UPDATE
So, after changing permissions on the file on google drive from accessible only to people who the file has been shared with to accessible/editable by all, I was able to access and download the file. Does the clients_secret.json file allow a particular google drive user to securely authorize or is that a general key that allows anyone with it to access the Google API in that particular session? Are there any special data that has to be send over the http request if the file has only been shared with a limited set of email addresses?
I also found handling idiosyncrasies of google drive api little bit tricky. I have written a wrapper around google drive api, which makes it relatively easy to deal with it. See if it helps:-
Google Drive Client
Sample code:-
file_id = 'abc'
file_access_token = '34244324324'
scope = 'https://www.googleapis.com/auth/drive.readonly'
path_to_private_key_file = '#'
service_account_name = '284765467291-0qnqb1do03dlaj0crl88srh4pbhocj35#developer.gserviceaccount.com'
drive_client = GoogleDriveClient(
scope = scope,
private_key = open(path_to_private_key_file).read(),
service_account_name = service_account_name)
file = drive_client.get_drive_file(file_id, file_access_token)
Ofcourse, you need to change access variables according to your profile.
In case anyone else has been having problems with this, changing the settings on the file in the drive to "everyone can view" solved the problem - seems that there were some permission restrictions. Would suggest that you look into changing the permissions on the file to the least restrictive setting (as possible) while debugging.
The python sample source code goes thru the details of authentication/etc. I am looking for a simple upload to the Google Drive folder that has public writable permissions. (Plan to implement authorization at a later point).
I want to replace the below code to upload file to Google Drive folder instead.
f = open('output.txt')
for line in allLines:
f.write (line)
f.close()
(If it makes any difference, I plan to run this thru Google App Engine).
Thanks.
You can't. All requests to the Drive API need authentication (source: http://developers.google.com/drive/about_auth)
As Wooble said, you cannot do this without authentication. You can use this service + file-upload widget to let your website visitors upload files to your Google Drive folder: https://github.com/cloudwok/file-upload-embed/