Giter Club home page Giter Club logo

dropboxrestapi's Introduction

DropboxRestAPI

About

DropboxRestAPI is a C# client for the Dropbox service through its RESTful API.

DropboxRestAPI aims towards being the most comprehensive implementation for the Dropbox REST API in .Net/C#.

Features

Contact

You can contact me on twitter @saguiitay.

NuGet

DropboxRestAPI is available as a NuGet package

Release Notes

  • 1.0.5 Fixed usage of 'cursor' parameter. Added support for SharedFolder information.
  • 1.0.4 Fixed issues with downloading of large files.
  • 1.0.3 Fixed issues with downloading of zero-bytes files.
  • 1.0.0 Initial release.

Usage

var options = new Options
    {
        ClientId = "...",
        ClientSecret = "...",
        RedirectUri = "..."
    };

// Initialize a new Client (without an AccessToken)
var client = new Client(options);

// Get the OAuth Request Url
var authRequestUrl = await client.Core.OAuth2.AuthorizeAsync("code");

// TODO: Navigate to authRequestUrl using the browser, and retrieve the Authorization Code from the response
var authCode = "...";

// Exchange the Authorization Code with Access/Refresh tokens
var token = await client.Core.OAuth2.TokenAsync(authCode);

// Get account info
var accountInfo = await client.Core.Accounts.AccountInfoAsync();
Console.WriteLine("Uid: " + accountInfo.uid);
Console.WriteLine("Display_name: " + accountInfo.display_name);
Console.WriteLine("Email: " + accountInfo.email);

// Get root folder without content
var rootFolder = await client.Core.Metadata.MetadataAsync("/", list: false);
Console.WriteLine("Root Folder: {0} (Id: {1})", rootFolder.Name, rootFolder.path);

// Get root folder with content
rootFolder = await client.Core.Metadata.MetadataAsync("/", list: true);
foreach (var folder in rootFolder.contents)
{
    Console.WriteLine(" -> {0}: {1} (Id: {2})", 
        folder.is_dir ? "Folder" : "File", folder.Name, folder.path);
}

// Initialize a new Client (with an AccessToken)
var client2 = new Client(options);

// Create a new folder
var newFolder = await client2.Core.FileOperations.CreateFolderAsync("/New Folder");

// Find a file in the root folder
var file = rootFolder.contents.FirstOrDefault(x => x.is_dir == false);

// Download a file
var tempFile = Path.GetTempFileName();
using (var fileStream = System.IO.File.OpenWrite(tempFile))
{
    await client2.Core.Metadata.FilesAsync(file.path, fileStream);
}

//Upload the downloaded file to the new folder

using (var fileStream = System.IO.File.OpenRead(tempFile))
{
    var uploadedFile =await client2.Core.Metadata.FilesPutAsync(fileStream, newFolder.path + "/" + file.Name);
}

// Search file based on name
var searchResults = await client2.Core.Metadata.SearchAsync("/", file.Name);
foreach (var searchResult in searchResults)
{
    Console.WriteLine("Found: " + searchResult.path);
}

dropboxrestapi's People

Contributors

b0r1k avatar richorama avatar saguiitay avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.