Getting refresh access token for Dropbox .net sdk, without intervention (back end service)

91 Views Asked by At

Hi i'm learning how to use the dropbox Api using the .Net sdk and i ran into the following

I setup a basic test using the .NET sdk from dropbox to test downloading files, my use case is that i'm using Asp.Net web api and im uploading images received to my own dropbox account, the code below is the test code that uses the "Generate access token" from the developer apps portal, this works but it is a short lived token.

Using the .net sdk how to implement refresh token, that would required no interaction from the user? all other answers here on stack overflow and developer community from dropbox dont handle this case. given my understanding the OAuth flow should only be needed for interacting with users dropbox since i'm using my own i should be able to access it without any manual intervention

 try
        {
            var filePath = $"PATH";
            var dbx = new DropboxClient("TOKEN");

            var response = dbx.Files.DownloadAsync(filePath).Result;

            if (response.Response.IsFile)
            {
                var fileContent = response.GetContentAsByteArrayAsync().Result;
                var fileName = Path.GetFileName(filePath);
               
                string base64String = Convert.ToBase64String(fileContent);
                return Ok(base64String);
            }
            else
            {
                
                return BadRequest("Requested item is not a file.");
            }
        }
        catch (Exception e)
        {
            throw new InternalServerException(e.Message);
        }

any help is appreciated (and yes i've read the docs but im still struggling with this)

1

There are 1 best solutions below

0
On BEST ANSWER

Since posting this question here and on the dropbox forum, i found the following so post here i did not understand before is that u need to follow the flow described there once just to get a refresh token which would last forever now in you're code you can use it

 var dbx = new DropboxClient(refresh_token, app_key, app_secret);

then same code as in question

additional link from the answer on dropbox forum here