I try to make integration with OneDrive, using the API https://dev.onedrive.com/getting-started.htm
I make auth work and i can get list of drives in the account .
When i execute the API call /me/drives i am getting the list of drives fine.
But i can not find how to get list of folders on a drive, subfolders of a folder etc.
From the docs i can see there are some API for this, but it doesn't work for me.
https://dev.onedrive.com/items/list.htm
I have to execute on of.
GET /drive/items/{item-id}/children
GET /drive/root:/{item-path}:/children
But it doesn't work. I have a Drive ID from a list of drives. When i execute
GET /drive/items/DRIVEID/children
i have error "Access denied. You do not have permission to perform this action or access this resource."
How to do this operation? should i use a drive ID or name? maybe the url is wrong, what must be the correct url if i have a drive name, ID ?
I have found how to do this. To understand i had to install some other tool where OneDrive API is used and debugged traffic with a https sniffer.
So, if endpoint is https://graph.microsoft.com/v1.0/me/
then paths are
/drives/DRIVEID/root/children
for root of drive
/drives/DRIVEID/root:myfolder/subfolder:/children
for a folder myfolder/subfolder
Final url is like
https://graph.microsoft.com/v1.0/me/drives/DRIVEID/root:myfolder/subfolder:/children
/drive is a shortcut for saying /drives/<driveidofcaller>. When you're attempting to query someone elses drive you'd want /drives/DRIVEID, and so extending to your example you'd want something like:
GET /drives/DRIVEID/root/children
Related
My app is using client_credentials, and is successfully consuming the Graph API on most calls.
However, I have been attempting to get images from a sharepoint folder by path and filename:
https://graph.microsoft.com/v1.0/drive/root:/sites/folder1/folder2/folder3/folder4/photo.jpg
The appropriate headers are being set (authorization and accept).
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + session["access_token"]);
httpClient.DefaultRequestHeaders.Add("accept", "application/json; odata.metadata=minimal");
The request returns a 404 - Not found response.
When I navigate to our sharepoint site, I can see the image fine so I can only assume the file path is correct:
https://ourcompany.sharepoint.com/sites/folder1/folder2/folder3/folder4/photo.jpg
Apologies, but I am new to Graph API and couldn't find anything referencing this in the documentation:
https://learn.microsoft.com/en-us/graph/api/resources/onedrive?view=graph-rest-1.0
Path
/me/drive/root:/path/to/file
Resource
Access a DriveItem by path relative to the user's OneDrive root folder.
Are there special permissions needed for this? I found something suggesting permissions might be required in azure portal but this is to do with azure active directory and I'm not sure if it will affect the graph API, as it was working OK, reading drives and drive items in sharepoint (by drive id and drive item id, not by file path).
EDIT: Went into azure portal, added Graph API permissions to application:
Site: ReadAll
Directory: ReadAll
File: ReadAll
No change so far.
A site contains the drive so you're referencing things in the wrong order. To get a DriveItem from a site's drive, you want this:
/sites/{siteId}/drive/root:/folder1/folder2/folder3/folder4/photo.jpg
If you're looking to download the DriveItem instead of just retrieving the metadata, you'll want this:
/sites/{siteId}/drive/root:/folder1/folder2/folder3/folder4/photo.jpg:/content
I have a written code to rename files of onedrive logged in user, using graph api with following call.
www.graph.microsoft.com/v1.0/me/drive/items/{FileOrFolderID}
with body:
{
"name":"newfilename.txt",
"#name.conflictBehavior": "rename"
}
I'm not able rename the files which has been shared by some other onedrive user with me, which I can if done in browser. The other user has given me editable permissions.
I have tried following syntax to rename file shared with me, but it gives me access denied error.
www.graph.microsoft.com/v1.0/me/drives/{DriveId}/items/{FileOrFolderID}
Can someone please answer what thing I am missing.
A couple of things to try:
Make sure you're requesting Files.ReadWrite.All if you need to modify someone else's items
Try hitting https://graph.microsoft.com/v1.0/drives/{DriveId}/items/{FileOrFolderID}. Using "me" may work, but it's semantically weird.
If neither of those work please update your question to include the full response so we can debug further.
Maybe you can try the character as follow, the full description refer to Update DriveItem properties
This example renames the DriveItem resource to "new-file-name.docx".
PATCH /me/drive/items/{item-id}
Content-type: application/json
"name": "new-file-name.docx"
Regards,
Leon
Does anyone know if Brackets Shell uses any URI except the file://...index.html format? I want to point a web service back to the shell and need to provide a valid URI with the URL. The problem is that I noticed that the URL for the index file uses basic system paths and this can change per system or user configuration.
Any way around this little problem?
Edit:
I am trying to access the Instagram API through brackets shell. In order to gain an access token to the OAuth method they use I need to redirect the user to the Instagram Login page to log in then grant access and then Instagram will redirect them back to me based on the call back or redirect url provided from me. If it was as simple as providing just the URL when the call was made I would be fine however to get a client key (which is also needed to access the api) I need to provide the correct call back URL once the key is made and since the shell seems to have no custom file path it's almost impossible to predict the file path based on each users setup on their own pc's. I hope this made sense :)
I searched the source of the brackets-shell, but couldn’t find the startup path. A quick workaround would be adding a meta-refresh to your index.html which redirects to the corresponding URL of your web service.
For example:
<meta http-equiv="refresh" content="0; url=http://example.com">
If you don’t want to select your index.html each time you start your custom shell, you should place your index.html at
Mac: Brackets.app/Contents/dev/src/index.html or Brackets.app/Contents/www/index.html
Win: dev/src/index.html or www/index.html (these folders must be in the same folder as Brackets.exe)
Linux: dev/src/index.html or www/index.html (these folders must be in the same folder as the Brackets executable)
You can get the current location through javascript using
document.location.href
this will return a string like
"file:///C:/Program%20Files%20(x86)/YourApp/www/index.html"
which you might try sending to Instagram. I'm not sure if they will accept file URI's though.
I can create a Google Doc, but whenever I try to access the link I get a permission denied notice. Is there a way to make the document public to anyone who has a link with the ruby client api?
Thanks!
The code at https://developers.google.com/drive/v2/reference/permissions/insert shows how to add new permissions to a document using Ruby.
To make the documents available to everyone, you have to set the permission type to anyone.
I've built an integration using the Google Docs API (using GData) allowing users to create/edit documents from another application. Originally, when documents were deleted we would have them permanently deleted. They were no longer visible in Google Docs or Google Drive. Now when they are deleted using the Google Docs API, they are still present in the list of Documents in Google Drive. When you attempt to follow the link to the document you arrive at the "Sorry, the page (or document) you have requested does not exist." page.
Does Google Drive not honor the actions taken via the Google Docs API? Do I need to delete these documents using both the Google Docs API and the Google Drive API? What if the user has not migrated to Google Drive? Is there a way to tell if the have migrated? Or do I force them to migrate so I can use the Google Drive API to keep their Google Drive clean of these dead documents?
The Drive API and the Docs List API both operate on the same resources so you only have to use one of them (and we recommend the former).
With the Drive API you can trash or delete files. When you trash a file, it will still be listed in Google Drive with a label to mark it as in trash, so that you can still untrash it.
If you want to remove a file completely, you have to use the delete method.
I was having the same problem and I believe this is some kind of caching on the drive UI.
The file does appear to be deleted correctly and is not visible to the drive API.
The orphaned stubs eventually get deleted as the cache is cleared every so often.
I found that by removing the file from the parent and then deleting it meant that it was easier to see what was going on when using the drive UI whilst testing my app.
service.children().delete(folderId=parent_id, childId=file_id).execute()
service.files().delete(fileId=file_id).execute()
I was facing the same problem while using Google Drive APIs. I think when the Delete api deletes the document, their is still some linking with parent folder remains, so the browser renders the document. when I tired to delete the document with below piece of code, it properly works for me.
DriveService.Childern.Delete(parentResId, fileId).Fetch(); // fileId=>ResourceId of document to be deleted
This is a caching issue, the file has actually been removed. If you try to open the file in the Drive UI you should see something along the lines of "Sorry, the file you have requested does not exist."
It will clear itself soon.