I have a publicly shared OneDrive folder with some various sub-folders and files. I.e. I have shared it via a link, so anyone with this link can access them.
Is there a way I can access these files from either client-side JavaScript or some server-side code via a REST API of some sort? Without having to use any sort of user-specific credentials?
What I've been trying
I've been looking at the Accessing Shared Content page, and it looks like what I want, but can't figure out how to use it.
I've taken something that looks like an id from the shared URL, which looks to be a long hexadecimal number (which seems to be an id pointing at me?), an !, and then a number (which I assume has to do with the shared resource).
I've then tried to stick it in this URL:
https://api.onedrive.com/v1.0/shares/<id>/root?expand=children
But I get back a 400 Bad Request, so something isn't quite right...
I'm thinking maybe some sort of authentication is missing, but since the shared files are public, I don't users to have to login with their credentials, and can't of course use my own in code.
I've tried to register an app, where I get an application id (guid) and can generate Passwords and Key-Pairs. Was hoping maybe I could use that, but don't see in the API how and where to actually use those...
Goal
The shared folder contains sheet music for a choir, that I'm responsible for keeping updated (and OneDrive syncing is super handy here).
Some members aren't very computer savvy, so I'd like to make seeing and downloading these files as easy as possible. The shared link with a "go here to this other strange site and find the files there"-text sort of works, but I would much rather like to list the files directly in a member-only area of our website. Basically just "here are the files, click on one to download it".
Yes, you can use the REST API to access the contents of a folder.
The API is the one you mentioned, the shares API. However, it sounds like you are perhaps using the wrong ID.
The most straightforward way to do this is to follow the instructions to encode the actual sharing URL into a token. This way you create a base64 encoded version of the sharing link, append a "u!" to the front of that string, and then make the exact call you already mentioned. You'll get back a list of the files in the shared folder and you can go from there.
Here's an example of this:
Here's a sharing link to a folder in OneDrive with some photos in it.
https://1drv.ms/f/s!AtuAM_NacwVahiFpuMGS_BiQCwWu
To convert this URL into the API, you first base64 encode the URL and append u!
u!aHR0cHM6Ly8xZHJ2Lm1zL2YvcyFBdHVBTV9OYWN3VmFoaUZwdU1HU19CaVFDd1d1
Now you can use this URL as the sharing token, and expand children and thumbnails:
https://api.onedrive.com/v1.0/shares/u!aHR0cHM6Ly8xZHJ2Lm1zL2YvcyFBdHVBTV9OYWN3VmFoaUZwdU1HU19CaVFDd1d1/root?expand=children
Clicking on this bottom link should give you the JSON response, which includes the shared folder and the children inside the folder.
Related
Is there any way that I can find all subdirectories for one link? Should I get the permission? For example, in the lecture instructor opened the solutions by entering some keywords after www.site.com/keyword. Now I cannot remember the word, whatever I try, I cannot find, but I know there is a file. That's why I want to see the files, other pages for the link.
The only way to find out what resources are available on an HTTP server is to request a resource that tells you. There isn't anything particularly standard about web servers that will provide that, so you'll need to do something specific to the webserver you want the details from.
Note that not all servers will provide something like this.
The closest thing to a standard is that most servers, for a URL that maps on to a directory on their file system, if there isn't an index file in that directory, will generate an HTML document containing a list of links to the resources in that directory.
I'm trying to integrate Dropbox into my web application in the following way:
Users can enter a Dropbox Share Link, i.e. a Dropbox folder that can be accessed by anyone, even without a dropbox account.
My application then grabs the images from the folder and displays them to all users of my application.
Now as far as I can tell, the Dropbox API doesn't allow this without sending the user through a full-blown OAuth process. But since the shared link is public anyway, I don't need (and don't want) access to the users Dropbox account.
Is there a way to access a shared link in a programmatic way (without parsing the DOM or similar hacks)? Maybe there is a query parameter on the shared link to retrieve the contents as JSON? If it exists, I didn't find any docs about it.
Surely I'm not the first one to try this, so please share your solutions!
No, there's no programmatic way to list folder contents from a share link. If you have a share link for a specific file, then you can convert the domain from www.dropbox.com to dl.dropboxusercontent.com, but this trick doesn't work on folders.
We are building a web application that should get all files from a specific folder in our Drive (read only). The problem is that I can't find a way to access our files without using OAuth. Basically I would want to request our files using AJAX and present the contents of them on a page (without the user having to do anything). Is this at all possible and have I missed something?
Whenever I try something without using OAuth I get a global internalError (being related to authorization according to the current documentation).
The experience I'm trying to achieve:
User enters http://domain.com/posts > Get all public files from folder Y > Sort them by date > Show the titles in HTML > User clicks title > User is presented with full contents of the file as HTML.
Is this possible?
Thanks in advance! :)
UPDATE:
To clarify: I would want to depend on our API key only.
You can do it this way, without using Google Drive API:
Make the folder public
Copy the folder ID from the URL
Append it to https://googledrive.com/host/ e.g. https://googledrive.com/host/0BzEbtMoF6IXbaVN2Qmx1em9qS0k/
You will get a directory index with all files listed and if the (sub)folder contains an index.html file, it will be rendered instead.
To get the JSON or XML file list, use YQL.
I'm writing an iPhone app, MyApp, which needs access to documents on and off-line. My users are already managing these documents (pdf's, movies, etc) via the Box iPhone app synching with the company server.
If MyApp knows the path & filename of a document, is it possible to use the Box URL Schemes to launch Box and open the document externally?
MyApp doesn't need to store or access the files and since Box already has the files downloaded, there's no point storing them in the Document space of both apps.
If there is such a URL Scheme, two follow up questions are: A) is there a callback to return to MyApp when the document is closed, and B) can MyApp use another URL Scheme to get a list of documents?
NSURL *ourURL = [NSURL URLWithString:#"box://some/path/to/fileid?callback=myapp://"];
if ([ourApplication canOpenURL:ourURL]) {
[ourApplication openURL:ourURL];
}
If this isn't currently possible, but of interest to Box, I'm interested in being a beta tester/early adopter.
If you just want to direct the user to a Box page, you may be able to direct the user to a specific file in one of two ways:
1) If the file is shared in Box and you have the shared name, you can generate a shared url (see sharing in the docs at developers.box.com). This only works for files that were shared, however.
2) If you have the file id of the file in Box, you can generate a URL to which the user can login to one's Box account and view the content. You can determine that URL by going into Box and seeing how URLs are displayed when you click on a particular file. We don't like to advertise that URL for developers, however, because we don't guarantee that this URL format will be maintained in the future. It hasn't changed in a while, so it's probably safe to use, but Box provides that "use it at your own risk" disclaimer.
Unfortunately, Box doesn't have a way to pull up a file based on file path. You need the file id or shared name. There isn't a url that relies on file or folder names.
I can't find the answer to this in the API docs or elsewhere. I see in the docs says you can get a downloadURL of a file, but it refers to it as a 'short lived URL'. What does that mean?
I need to upload images and get a permanent URL of that image that is the direct URL than can be embedded into emails or web docs etc. Is that possible?
Thanks
Yes, you can get a permalink to any file hosted on Google Drive in a public folder. Just note the folderID:
and paste it to the following URL:
http://googledrive.com/host/<folderID>/<filename>
or you can create a short custom alias using G Drives: http://gdriv.es/<alias>/<filename>
https://developers.google.com/drive/v2/reference/files#webContentLink
downloadUrl is short lived, but webContentLink is a permanent link. It's odd that one is a URL and the other is a "link", but I guess it probably has to do with the additional query params in the strong. Maybe that makes it not just a URL? :)
That property is only available for files that are publically readable, so you may have to use the SDK/API to set the permissions first.
In case someone encounter the same problem and don't want to do with deprecated Google Drive solution above and requires frequently changed files with exact same url, you can use Dropbox. Steps:
Download the program and share a folder (tutorial)
Copy a file into that folder; wait for sync with Dropbox
Go to your dropbox.com account
Share your file by button, get something like:
https://www.dropbox.com/s/d28d8scvr3rfy48/foo.exe?dl=0
Rename it to:
https://dl.dropboxusercontent.com/s/d28d8scvr3rfy48/foo.exe?dl=0
Now you have a public, unchanged url for all your foo.exe changes.
Enjoy, don't waste time with sites offering you file hosting and they change the URL for same files.
If you share a file publicly in GDrive, you can use the following link to make the file download directly:
https://drive.google.com/uc?export=download&id=FILEID
The problem happens when you want to change the file (for version controlled download, in instance) and keep the same downloading link.
You can use a URL Shortener like bitly.com and use a Branded Bitlink to change the destination URL keeping the input URL.
I hope it works, good luck!
It seems if you have file ID you can access it with such url:
https://drive.google.com/open?id=file-id-here
If file is public, you'll see it immediately but if not, you're be asked to login
I don't know how often this changes but I was looking for a dynamic solution where I wouldn't need to manually upload to another site and the provided solutions weren't working.
Here's the url that worked for me:
https://lh3.google.com/u/0/d/<file_id>
Where file_id is the getId() using the google apps script drive API. Secondly the file must be shared publicly like posted previously
Secondly I imagine the lh3 are different cdn's though I cannot confirm since lh1/2 don't work and everything higher than 3 redirects to lh3
I don't know if such API for google drive exists, but I think you should also have a look at dropbox,
which will meet all the demands that you mention in your question.
Also there are some very cool applications developed just for dropbox, like pancake.io which lets you share links of text, html files, in an html page format.
that + permanent link is always there.
You can use gdriveurl.com, it got updated and now allows users to log in with their google drive account and share the list of files instantly, getting for each file "View" & "Download" short permalink.
There's also the old solution (login to Google Drive, set everything to "Public on web", copy share link, convert it into the gdriveurl.com textarea in the homepage), but it's just a waste of time, you should try "MyDrive" api.
Not sure if the link generated here is guaranteed to be permanent, but Google Drive Direct Link Generator does the job of generating a direct download link.
Just make sure your file's sharing setting is set to Anyone with the link