Google Drive SDK File.List properties - google-drive-api

I'm using v2 of the Google Drive SDK for C#.
I get a FilesResource.List request from the Files.List().Execute().
The actual REST API shows the "properties" field should be included with this response; however, I cannot find any properties field on each item in enumerable collection of request.Items[x] in Drive.v2.Data.File.cs.
How can I get the properties from the initial request?

By calling Files.List().Execute() you are getting back a list of Files.
File contains several properties including "AlternateLink", "DownloadUrl", "Properties" and others. Your ListRequest object (which is returned from Files.List()) contains all the different properties you can set.
Please attach code to make your question more clear.

My goof I overlooked the field.
Get a file via list or creation
Google.Apis.Drive.v2.Data.File newFile = new Google.Apis.Drive.v2.Data.File();
Then
List lstMetadata = (newFile.Properties == null) ? new List() : newFile.Properties.ToList();

Related

Autodesk Forge - downloaded item has a different name

I'm using the https://developer.api.autodesk.com/oss/v2/buckets/:bucketKey/objects/:objectName endpoint to download an item (a Revit model) from BIM 360. Using this documentation. The file gets downloaded fine and the contents are correct however, after downloading, the file name is the GUID of the file (4aac519c-ab91-42a5-85c5-f023c82d4736.rvt) , not the 'displayName' of the file (my file.rvt) . I'm getting the file name like so:
var headervalue = resp.Headers.FirstOrDefault(x => x.Name == "Content-Disposition")?.Value;
string contentDispositionString = Convert.ToString(headervalue);
ContentDisposition contentDisposition = new ContentDisposition(contentDispositionString);
fileName = contentDisposition.FileName;
I've used the same method on another project and it's working fine. The content and the file name of the file both are correct. However somehow the endpoint is behaving differently on this project.
Any pointers what could be the issue here?
I'm not sure if this is mentioned somewhere in the documentation but I don't think you should rely on the Content-Disposition of the response headers for this. If you want to get a filename for whichever object you're downloading, you should always get it from the actual item record (obtained in the 3rd step of the tutorial you linked to).

How to set description in the BoxFileUpload request?

I am using the Box windows V2 SDK to upload files to my Box account using the following code:
BoxFileRequest request = new BoxFileRequest()
{
Parent = new BoxRequestEntity() { Id = "0" },
Name = attachment.Name,
Description = "This is failing to be sent..."
};
client.FilesManager.UploadAsync(request, new MemoryStream(attachment.FileContent)).Result;
Uploading the file works great. However, I can not get the description field sent to the box server. Is it possible to upload a file with a description, or do I have to call FilesManager.UpdateInformationAsync after the file has been uploaded to accomplish this? It would be nice if this was an option so I could reduce the number of API calls..
The description must be set in a separate API request after uploading the file.
We have heard reusing some of the request objects may cause some confusion on what can be done with each request. We are evaluating whether or not this should be changed

How to get collaboration ID using box api

I am trying to get the collaboration for a given folder. In the Box sdk given on github the function is public Collaboration GetCollaboration(string collaborationId, IEnumerable fields = null). My question is how do i get the collaboration ID??? After reading the comments in [link] Is there any way to get all files and folder in box without knowing their id? I thought the ID of a given folder is to be given but when i provide that I get an exception "404 not found". Although my folder id "867049500" does have a collaboration enabled. Please see the image below
The official Windows SDK provides a method that will fetch the collaborations for a known folder:
var client = new BoxClient(...);
var collabs = await client.FoldersManager.GetCollaborationsAsync(folderId);
(Edited 8/29/14 to point to official SDK)
Rather than this i have been able to explore an alternative for this:
var boxManager = new BoxApi.V2.BoxManager(userToken);
From the above code you get the boxManager, and further:
var testFolder = boxManager.GetFolder(FolderID);
From the above code you get the Folder, and further pass it as shown below:
CollaborationCollection sampleCollabs = boxManager.GetCollaborations(testFolder, false, null);
It has worked out for me, so i am sharing the solution.
Using Python, the following can get the collaboration attributes.
Step 1 : Use get_collaborations() method which returns a collaborations collection
collaborations = client.folder(folder_id='Your_target_folder_id').get_collaborations()
Step 2 : Then iterate over collaborations to get the specific collaboration ID
for collab in collaborations:
collaboration_id = collab.id

Not receiving "webViewLink" in response?

After turning on Google Drive API access from the management console and getting my Client ID keys, I followed the sample code (using Python 2.7) and I am able to insert a folder, set the appropriate permissions (type=anyone,role=reader), and insert a text/html type file into the new folder.
However the JSON file resource objects I receive from executing insert on the drive service have no 'webViewLink' field! There are 'webContentLink' and 'selfLink' fields but 'webViewLink', which is necessary for static HTML publishing, seems to be missing.
Most perplexing. If this feature hasn't been turned on yet or if I need to configure my account settings to allow HTML publishing please let me know. Any other help would be most appreciated ;)
The webViewLink property is only returned for public folders, and not the single files inside such folders. You can use that as the base url to construct links to your files.
The WebViewLink file property can be retrieved by doing something like this:
$file = $service->files->get($file_id, array('fields' => 'webViewLink'));
$web_link_view = $file->getWebViewLink();
OR
$sheetsList = $drive_service->files->listFiles([
'fields' => 'files(id, name, webViewLink, webContentLink)',
]);
$web_link_view = $sheetsList->current()->getWebViewLink();
Pay attention that you should load the file specifying which fields you wanna bring with it (In this case, webViewLink). If you don't do that, only id and name will be available.
If you also need to configure file permissions, you can do something like:
$permissions = new \Google_Service_Drive_Permission();
$permissions->setRole('writer');
$permissions->setType('anyone');
$drive_service->permissions->create($file_id, $permissions);
Possible values for setRole() and setType() can be found here: https://developers.google.com/drive/api/v3/reference/permissions/create

How to add a doc to a folder

I am generating a document using Google App Script (specifically a document, not a spreadsheet) and I need to be able to add it to a folder I have called "Test Documents".
I have tried
doc.addToFolder("Test Documents");
However, in debug mode I get the error that the method addToFolder is not found. I'm trying to use this functionality: https://developers.google.com/apps-script/class_file#addToFolder
Could someone give me an example of how I might do this?
The method addToFolder is part of DocsList service, here is an example :
var Doc = DocsList.getFileById('1INkRIviwdjMC-PVT9io5LpiiLW8VwwIfgbq2E4xvKEo');
var gas = DocsList.getFolderById('0B3qSFd3iikE3NWY0dndsMTFZMDQ')
Doc.addToFolder(gas)