Code Monkey home page Code Monkey logo

dropnetrt's Introduction

Note: Development of DropNet has stopped!

DropNet is no longer under development and the current version of the library does not work with Dropbox API v2. I recommend moving to the official Dropbox .net SDK - https://github.com/dropbox/dropbox-sdk-dotnet


.NET Client library for the Dropbox API

Build status

Full documentation here: http://dropnet.github.io/dropnet.html

How do I use it?

The Client:

To use DropNet you need an instance of the DropNetClient class, this class does everything for DropNet. This class takes the API Key and API Secret (These must be obtained from Dropbox to access the API).

    _client = new DropNetClient("API KEY", "API SECRET");
Login/Tokens:

Dropbox now requires a web authentication to get a usable token/secret, so this is a 3 step process.

Step 1. Get Request Token - This step gets an oauth token from dropbox (NOTE: the token must pass the other steps before it can be used)

    // Sync
    _client.GetToken();
    
    // Async
    _client.GetTokenAsync((userLogin) =>
        {
            //Dont really need to do anything with userLogin, DropNet takes care of it for now
        },
        (error) =>
        {
            //Handle error
        });

Step 2. Authorize App with Dropbox - This step involves sending the user to a login page on the dropbox site and having them authenticate there. The DropNet client has a function to return the url for you but the rest must be handled in app, this function also takes a callback url for redirecting the user to after they have logged in. (NOTE: The token still cant be used yet.)

    var url = _client.BuildAuthorizeUrl();
    //Use the url in a browser so the user can login

Open a browser with the url returned by BuildAuthorizeUrl - After we have the authorize url we need to direct the user there (use some sort of browser here depending on the platform) and navigate the user to the url. This will prompt them to login and authorize your app with the API.

Step 3. Get an Access Token from the Request Token - This is the last stage of the process, converting the oauth request token into a usable dropbox API token. This function will use the clients stored Request Token but this can be overloaded if you need to specify a token to use.

    // Sync
    var accessToken = _client.GetAccessToken(); //Store this token for "remember me" function
 
    // Async
    _client.GetAccessTokenAsync((accessToken) =>
        {
            //Store this token for "remember me" function
        },
        (error) =>
        {
            //Handle error
        });

Best Practices: Dropbox's Developer page states several times in bold red font that applications should not store a users Dropbox password and to help enforce this DropNet allows you to manually set a users Token and Secret on the client.

    _client = new DropNetClient("API KEY", "API SECRET", "USER TOKEN", "USER SECRET");
    // OR
    _client = new DropNetClient("API KEY", "API SECRET");
    _client.UserLogin = new UserLogin { Token = "USER TOKEN", Secret = "USER SECRET" };

Questions? http://stackoverflow.com/questions/tagged/dropnet

dropnetrt's People

Contributors

alex-netkachov avatar dalewking avatar dkarzon avatar hartez avatar janzeman avatar jaytwo avatar prashantvc avatar rasmuschristensen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dropnetrt's Issues

DropNetRT.Models.DeltaPageInternal.Entries seems to be of the wrong type

I'm getting errors using this, and it seems to be due to deserialization issues. This is the response that I get from Dropbox:

{   
    "has_more": true, 
    "cursor": "BLAGHABLAGAbigDarn-StringTHing123", 
    "entries": 
    [
        ["/exampleFile.pdf", {"revision": 1, "rev": "1131aa664", "thumb_exists": false, "bytes": 249159, "modified": "Mon, 12 Aug 2013 18:55:30 +0000", "client_mtime": "Mon, 12 Aug 2013 18:55:30 +0000", "path": \"/exampleFole.pdf\", "is_dir": false, "icon": "page_white_acrobat", "root": "dropbox", "mime_type": "application/pdf", "size": "243.3 KB"}],
        ["/examplefolder", {"revision": 2, "rev": "2131aa664", "thumb_exists": false, "bytes": 0, "modified": "Tue, 13 Aug 2013 17:30:35 +0000", "path": "/examplefolder", "is_dir": true, "icon": "folder_user", "root": "dropbox", "size": "0 bytes"}]
    ], 
    "reset": true
}

And this is the model:

internal class DeltaPageInternal
{
    public string Cursor { get; set; }
    public bool Has_More { get; set; }
    public bool Reset { get; set; }
    public List<List<string>> Entries { get; set; }
}

As you can see, Entries doesn't seem to be a List of Lists of strings.

Upload url for background transfers.

I'm writing app on Windows Phone 8.

I get upload url via UploadUrl method and add it to background transfers. I receive error code 400 when background transfer finish.

And why MakeUploadRequest method don't use filename parameter?

Add support for getting oauth2 token

I am trying to use another API in conjunction with DropNetRT and the other API needs the OAuth2 bearer token which can be obtained from the oauth1 token using a simple call (https://www.dropbox.com/developers/core/docs#oa2-from-oa1). For me to make that call requires duplicating functionality that already exists in DropNetClient, but which is made private and inaccessible.

Would be very convenient if this call were added to DropNetClient.

Unable to use DropNetRT w/o forking it and updating its references to the latest NuGet packages of Microsoft.Net.Http and Newtonsoft.Json.dll

We use these libraries in other parts of our product, and it seems that w/o forking DropNetRT and changing its NuGet references it is impossible to use DropNetRT in our project.

Is it an expected behavior?

System.IO.FileLoadException: Could not load file or assembly 'System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. 

Here's an example of our error log:

DEBUG   2016-01-14 04:53:47Z EXCEPTION: System.IO.FileLoadException: Could not load file or assembly 'System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at ZU.Apps.Dropbox.DropboxApp.<TrySignIn>d__111.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
   at ZU.Apps.Dropbox.DropboxApp.TrySignIn(String userToken, String userSecret)
   at ZU.Apps.Dropbox.DropboxApp.TrySignInAsync() in C:\stuff\dev\zu_src\ZU\ZU.Core.Apps.Dropbox\DropboxApp.Internal.cs:line 420
   at ZU.Apps.Dropbox.AppPane.dropboxApp_Loaded(Object sender, RoutedEventArgs e) in C:\stuff\dev\zu_src\ZU\ZU.Core.Apps.Dropbox\AppPane.xaml.cs:line 177
   at ZU.Apps.Dropbox.DropboxApp.Initialize(IAppSettings settings, ISystemInformationModel sim, IAppManager appManager) in C:\stuff\dev\zu_src\ZU\ZU.Core.Apps.Dropbox\DropboxApp.cs:line 555
   at ZU.Apps.Dropbox.DropboxApp.OnConnection(ConnectMode mode) in C:\stuff\dev\zu_src\ZU\ZU.Core.Apps.Dropbox\DropboxApp.ZetApp.cs:line 48
   at SAL.Flatbed.PluginStorage.InitializePlugins()

=== Pre-bind state information ===
LOG: DisplayName = System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/stuff/dev/zu_src/Drops/Latest/
LOG: Initial PrivatePath = NULL
Calling assembly : DropNetRT, Version=1.5.20.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\stuff\dev\zu_src\Drops\Latest\ZetUniverse.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/stuff/dev/zu_src/Drops/Latest/System.Net.Http.Primitives.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

Provide information about Modifier to Metadata

Since July 2014, Dropbox Core API supports Modifier data for files in personal accounts. This is available only to those apps that requested permission for that, but this is a very, very useful feature.

For now, I used the following approach:

  1. own method to obtain metadata
  2. own class with metadata
  3. method:

private async Task GetMetadataEx(string relativePath)
{
string webFilePath = relativePath.Replace("", "/");

        HttpClientHandler handler = new HttpClientHandler();

        // OAuth
        DropNetRT.Authentication.OAuthMessageHandler oauthHandler =
            new DropNetRT.Authentication.OAuthMessageHandler(handler, apiKey, apiSecret, client.UserLogin.Token, client.UserLogin.Secret);

        HttpClient c = new HttpClient(oauthHandler);

        string str = string.Format("https://api.dropbox.com/1/metadata/auto/{0}", webFilePath);

        HttpRequest httpRequest = new HttpRequest(HttpMethod.Get, str);

        // we don't need list
        httpRequest.Parameters.Add(new HttpParameter("list", (object)false));
        //httpRequest.Parameters.Add(new HttpParameter("include_deleted", (object)includeDeleted));

        // we need membership data
        httpRequest.Parameters.Add(new HttpParameter("include_membership", (object)true));

        HttpResponseMessage httpResponseMessage;
        oauthHandler.Authenticate(httpRequest);
        try
        {
            httpResponseMessage = await c.SendAsync(httpRequest);
        }
        catch (Exception exception)
        {
            //throw new DropboxException(exception);

            return null;
        }
        if (httpResponseMessage.StatusCode != HttpStatusCode.OK)
        {
            return null;
            //throw new DropboxException(httpResponseMessage);
        }

        string responseString = await httpResponseMessage.Content.ReadAsStringAsync();


        var metadataEx = JsonConvert.DeserializeObject<DropboxMetadataEx>(responseString);

        return metadataEx;
    }
  1. extended metadata class:

    public class DropboxMetadataEx : DropNetRT.Models.Metadata
    

    {
    [JsonProperty("modifier")]
    public Modifier Modifier
    {
    get;
    set;
    }

    } // class

    public class Modifier
    {
    [JsonProperty("display_name")]
    public string DisplayName { get; set; }
    [JsonProperty("uid")]
    public string Uid { get; set; }
    } // class

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.