新しいBoxサポートサイトへようこそ。 変更点の詳細はこちらをご確認ください .

How Can I Automate the Download of Contents of a Shared Folder?

回答済み
新規投稿

コメント

5件のコメント

  • jcleblanc

    Hi ,

     

    There could be a number of reasons for this:

    1. The user that the access token is scoped for is not the correct user. This happens a lot with JWT applications where you auth as the enterprise, which refers to the app service account (which won't have access) instead of the user account (which will have access).
    2. The token or user account doesn't have all of the necessary permissions to access the data.

    Can you supply the code that you're using in the app to authenticate and make the folder call to Box please?

     

    Thanks,

    Jon

    0
    コメントアクション Permalink
  • tvaidyan

    Thanks for your response.  Here are my code snippets below, where I'm making a connection and attempting an enumeration of the folder contents.  I'm using C# /.NET SDK.

     

    1.  Initializing Connection:

    static void InitializeBoxConnection()
    {
    	var reader = new StreamReader("box-config.json");
    	var json = reader.ReadToEnd();
    	var config = BoxConfig.CreateFromJsonString(json);
    
    	var sdk = new BoxJWTAuth(config);
    	var token = sdk.AdminToken();
    	var session = new OAuthSession(token, "N/A", 3600, "bearer");
    
    	// FYI, boxUserId is set to: 11584666986, which is the same user account that I
    	// login with manually and access these shared files from.
    	boxClient = new BoxClient(config, session, asUser: boxUserId);
    }

    2.  Trying to access my root folder and enumerate its contents:

    static async Task GetFiles()
    {
    	StandardOutput.Trace($"Getting files from Box, folder: 0");
    
    	try
    	{
    		var items = await boxClient.FoldersManager.GetFolderItemsAsync("0", 5000);
    
    		Console.WriteLine($"TotalCount: {items.TotalCount}"); // it correctly shows 3 here.  2 shared folders and 1 local folder.
    
    		Console.WriteLine($"Entries collection count: {items.Entries.Count}"); // but the entries collection only shows 1
    		foreach (var item in items.Entries)
    		{
    			Console.WriteLine($"name: {item.Name}"); // my local folder name gets printed out here.
    		}
    	}
    	catch (Exception e)
    	{
    		throw;
    	}
    
    	return true;
    }

    3.  When I try to access a remote folder explicitly by it's ID:

    static async Task GetFiles()
    {
    	//StandardOutput.Trace($"Getting files from Box, folder: {boxFolderId}");
    	StandardOutput.Trace($"Getting files from Box, folder: 91493678311");
    
    	try
    	{
    		var items = await boxClient.FoldersManager.GetFolderItemsAsync("91493678311", 5000);
    
    		Console.WriteLine($"TotalCount: {items.TotalCount}");
    
    		Console.WriteLine($"Entries collection count: {items.Entries.Count}");
    		foreach (var item in items.Entries)
    		{
    			Console.WriteLine($"name: {item.Name}");
    		}
    	}
    	catch (Exception e)
    	{
    		throw;
    	}
    
    	return true;
    }

    I get this error:

    Box.V2.Exceptions.BoxException: The API returned an error [NotFound | 1wbd6ngbn5817vpy.0c91724ff88b11bc7aab19a9c11a3a373] not_found - Not Found
    at Box.V2.Extensions.BoxResponseExtensions.ParseResults[T](IBoxResponse`1 response, IBoxConverter converter)
    at Box.V2.Managers.BoxResourceManager.ToResponseAsync[T](IBoxRequest request, Boolean queueRequest)
    at Box.V2.Managers.BoxFoldersManager.GetFolderItemsAsync(String id, Int32 limit, Int32 offset, IEnumerable`1 fields, Boolean autoPaginate, String sort, Nullable`1 direction)
    at Cerner.DocumentAcquisition.Program.GetFiles() in C:\Development\Cerner.DocumentAcquisition\Program.cs:line 47
    --- End of inner exception stack trace ---
    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
    at System.Threading.Tasks.Task`1.get_Result()
    0
    コメントアクション Permalink
  • tvaidyan

     or others - Any thoughts on the snippets that I provided above?  We've  been stuck for a week and is hoping for an assist from someone.

    0
    コメントアクション Permalink
  • jcleblanc

    Hi ,

     

    Let's try to simplifying things a bit. Instead of using the as-user option, can you instead use the user access token method described here. There's some visibility issue happening with the user you're trying to use and the folder, so let's see if the above guide helps.

     

    Also, what line is the error response referring to here:

     

    Program.cs:line 47

     

    - Jon

    0
    コメントアクション Permalink
  • tvaidyan

    You da man Jon!  I was able to get past this problem by using the alternate approach you suggested... which is, instead of doing this:

     

    // DOES NOT WORK
    
    var reader = new StreamReader("box-config.json");
    var json = reader.ReadToEnd();
    var config = BoxConfig.CreateFromJsonString(json);
    
    var sdk = new BoxJWTAuth(config);
    var token = sdk.AdminToken();
    var session = new OAuthSession(token, "N/A", 3600, "bearer");
    
    boxClient = new BoxClient(config, session, asUser: boxUserId);

     

    Do this instead:

    // THIS WORKS !!!!!!!!
    
    var reader = new StreamReader("box-config.json");
    var json = reader.ReadToEnd();
    var config = BoxConfig.CreateFromJsonString(json);
    
    var sdk = new BoxJWTAuth(config);
    var token = sdk.UserToken(boxUserId);
    boxClient = sdk.UserClient(token, boxUserId);

     

    This may still be something for your team at Box to investigate as to why the first approach doesn't work but thanks for suggesting an alternate approach that works for my specific situation.  Much appreciated!

    0
    コメントアクション Permalink

サインインしてコメントを残してください。