How to get collaboration ID using box api - 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

Related

Folder.Bind Method in Graph SDK client using C#

We need folder.bind similar method in Graph SDK using C#.
Below method works with Outlook Exchange services but for O365 user its not working.
var msgRootFId = new EWS.FolderId(EWS.WellKnownFolderName.MsgFolderRoot, new EWS.Mailbox(SMTPAddress));
msgRoot = EWS.Folder.Bind(service, msgRootFId, EWS.BasePropertySet.IdOnly);
You can call one of the following endpoints. Instead of id you can use well-known folder name msgfolderroot
GET /me/mailFolders/{id}
GET /me/mailFolders/msgfolderroot
GET /users/{id | userPrincipalName}/mailFolders/{id}
GET /users/{id | userPrincipalName}/mailFolders/msgfolderroot
Resources:
mailFolder resource type
get mailFolder

Socrata Open Data API Resource ID Generation

I am new to Socrata Open Data. I am trying to access a dataset from NYC DOB Violations. I registered myself and have an App Token and I know the endpoint.
public ResourceMetadata GetMetadata(string resourceId)
{
if (FourByFour.IsNotValid(resourceId))
throw new ArgumentOutOfRangeException("resourceId", "The provided resourceId is not a valid Socrata (4x4) resource identifier.");
var uri = SodaUri.ForMetadata(Host, resourceId);
var metadata = read<ResourceMetadata>(uri);
metadata.Client = this;
return metadata;
}
How do I get the resource ID? I have a dataset I am interested in and I would like to Programmatically download the file every month?
I downloaded the .Net Library and SDK but am not able to figure out a way to do that .
Please help.
You can get the resource identifier from the API docs for that dataset:
https://dev.socrata.com/foundry/data.cityofnewyork.us/dvnq-fhaa
The identifier is the eight alphanumeric questions separated into two groups of four after /resource/. For that dataset, it would be dvnq-fhaa.
Good luck!

Google Drive Folders/Files Created Using API Not Visible on Google Interface

This is rather strange. I used Google Drive API to create a folder in Google Drive and then uploaded a file there. I can retrieve the folder and file using the same API (the code is working fine in all respect). However, when I go to Google Drive Web interface, I can't seem to find the folder or file. The file also doesn't sync to my local drive. Is there a setting in API or elsewhere to set the "visibility" ON?
Thank you in advance.
I had the same issue. Turned out to be permissions. When the file is uploaded by the service account, the service account is set as the owner, and then you can't see the files from the Drive UI. I found the solution online (but can't seem to find it again...)
This is what I did...
It's C#, your question didn't specify. The code you're interested in is the permission stuff after you get the response body after the upload...
FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain");
request.Upload();
//Start here...
Google.Apis.Drive.v2.Data.File file = request.ResponseBody;
Permission newPermission = new Permission();
newPermission.Value = "yourdriveaccount#domain.com";
newPermission.Type = "user";
newPermission.Role = "reader";
service.Permissions.Insert(newPermission, file.Id).Execute();
The file was visible on the Drive UI after this. I tried specifying "owner" for the role, like the api suggests, but I got and error saying that they're working on it. I haven't played around with the other setting yet, (I literary did this last night). Let me know if you have any luck with any other combinations on permissions.
Hope that helps
I had the same issue, but this got solved my using a list data type for parents parameter, eg: If one wants to create a folder under a folder("1TBymLMZXPGkouw-lTQ0EccN0CMb_yxUB") then the python code would look something like
drive_service = build('drive', 'v3', credentials=creds)
body={
'name':'generated_folder',
'parents':['1TBymLMZXPGkouw-lTQ0EccN0CMb_yxUB'],
'mimeType':'application/vnd.google-apps.folder'
}
doc = drive_service.files().create(body=body).execute()
While permission issue is the main cause of this problem. What I did to make the folders or files appear after I uploaded it with service account was to specify the parent folder. If you upload / create folder / files without parent folder ID, that object's owner will be the service account that you are using.
By specifying parent ID, it will use the inherited permissions.
Here's the code I use in php (google/apiclient)
$driveFile = new Google\Service\Drive\DriveFile();
$driveFile->name = $req->name;
$driveFile->mimeType = 'application/vnd.google-apps.folder';
$driveFile->parents = ['17SqMne7a27sKVviHcwPn87epV7vOwLko'];
$result = $service->files->create($driveFile);
When you create the folder, you should ensure you set a parent, such as 'root'. Without this, it will be not appear in 'My Drive' and only in Search (Have you tried searching in the UI?)
Since you have already created the folder, you can update the file and give it the parent root as well.
You can test it out using the Parents insert 'Try it now' example.
Put your Folders ID in the fileId box, then in the request body, add root in the ID field.
private void SetFilePermission(string fileId)
{
Permission adminPermission = new Permission
{
EmailAddress = "test#gmail.com", // email address of drive where
//you want to see files
Type = "user",
Role = "owner"
};
var permissionRequest = _driveService.Permissions.Create(adminPermission, fileId);
permissionRequest.TransferOwnership = true; // to make owner (important)
permissionRequest.Execute();
Permission globalPermission = new Permission
{
Type = "anyone",
Role = "reader"
};
var globalpermissionRequest = _driveService.Permissions.Create(globalPermission, fileId);
globalpermissionRequest.Execute();
}

Google Drive SDK File.List properties

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();

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)