Coder Social home page Coder Social logo

dropnet'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

dropnet's People

Contributors

austhomp avatar briceattouchtech avatar chafey avatar crackalak avatar daviddesloovere avatar derigel23 avatar dipth avatar dkarzon avatar drfriedparts avatar grantcolley avatar jbct avatar jhoerr avatar jmacentee avatar mchristopher avatar mercan01 avatar michaelpereira avatar misterfoo avatar myownclone avatar nicwise avatar partyz0ne avatar petemill avatar philchuang avatar possan avatar runeborg avatar staticcat avatar tgnm avatar victorbello avatar zeroid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dropnet's Issues

Does Upload async have a bug with RestSharp interaction?

With an 8MB file, I am seeing the following exception while trying to use UploadAsync function.

It occurs both for the unit test and my code.

My guess is that some request queuing is taking longer than what the UploadAsync function implementation is not waiting correctly on.

My internet connection isn't the fastest (as a data point).

System.Net.WebException was unhandled
Message="The request was aborted: The request was canceled."
Source="System"
StackTrace:
at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)
at System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeState)
at System.Net.ConnectStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Stream.Dispose()
at RestSharp.Http.RequestStreamCallback(IAsyncResult result, Action`1 callback)
at RestSharp.Http.<>c__DisplayClass16.b__12(IAsyncResult result)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.HttpWebRequest.InvokeGetRequestStreamCallback()
at System.Net.HttpWebRequest.EndWriteHeaders_Part2()
at System.Net.HttpWebRequest.EndWriteHeaders_Part2Wrapper(Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
InnerException: System.IO.IOException
Message="Cannot close stream until all bytes are written."
Source="System"
StackTrace:
at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)
InnerException:

Uploading a file appends newline character at the end

When you upload a file via DropNetClient.UploadFile() the file gets uploaded, but a newline sequence "\n\r" is appended to the end of the file. When using binary files some applications can not open the file anymore and tell me that it is corrupted.

File Upload Issue

Hi All,
Can Any one pls check this issue....
I am getting "Authentication Failed Error" when uploading file. But i can sucessfully getting the Metadata of files & folders. & and i can create folder.. Only issue in File Upload..
here is my code..

//_Code_********//

StreamResourceInfo sr = Application.GetResourceStream(new Uri("Background.png", UriKind.RelativeOrAbsolute));
byte[] databytes = new byte[sr.Stream.Length];
sr.Stream.Read(databytes, 0, databytes.Length);
dc.UploadFileAsync(@"/MyFolder/", "Background.png", databytes, new Action(Result));

asynchronous file uploads don't work (file parameter value is invalid)

Using the DropNetCLI.exe client on Windows desktop, I changed c.UploadFile(remotepath, filename, data) to c.UploadFileAsync(remotepath, filename, data, null);

I know the null callback means the code will crash in RestClient.ProcessResponse(). I set a breakpoint before the callback and looked at the value of restResponse.Content, and I see:
Content "{"error": "file parameter value 'test.txt' is invalid"}"

I don't quite understand your code, but I looks like the synchronous code puts the parameters in the URI and the asynchronous code puts the parameters in the HTTP header, which apparently Dropbox can't handle.

Index out of bounds

I’ve noticed that I sometimes get an index out of bounds exception from RestSharp when I try to make a request to dropbox.

The exception can happen on all types of requests, “GetFile”, “GetMetaData” and so on. Even when I try again (in a try catch) the same exception occurs. So the only way is to restart the application (asp.net).

AccountInfo data types: long instead of string

I had to change the datatypes of some AccountInfo members from string to long. Because they were strings, JsonDeserializer cuts off the first and last character, expecting them to be quotes (but without really checking for them!). For small numbers (0, for example), this will give an error.

Forebbiden error

I am use DropNet 1.6 version in my current project (Windows Phone 7). When I am start download file with large name (near 15 chars), I am receive Forbidden error. How I can fix it. Thanks.

Lack of progress feedback for get file and upload file API

Hi. Currently your API does not return progress feedback for us to use and display via visual cue using progressbar. Dealing with small files is no problem with progressbar... But large files, we do not know what is the progress...

Able to implement a progress a feedback so a progress bar of that job can be shown. Thanks

GetFile should use api-content URL

My attempts to GetFile throw an exception with a response of: {"error": "Not Found"}.
Looking at the ResponseUri, it appears that GetFile is using:
https://api.dropbox.com/1/files/dropbox/...
when it should be using:
https://api-content.dropbox.com/1/files/dropbox/...

I am using the latest version of DropNet from NuGet. It appears to be the same version on GitHub (1.8.4).

Cheers. Thanks for this!

File Upload failure

Running the unit tests, the Can_Upload_File test fail because the response.StatusCode is equal to 0. Do you have the same problem on your computer ?

File in foreign language fails to upload / get metadata

Damian,
I tried to upload a file named in foreign language but it failed with invalid signature error.
This is because file name is not converted to UTF-8 before URL encode in OAuthAuthenticator.NormalizeRequestParameters.
As well as this reason, getting metadata for file or folder named in non ASCII fails.
To address this problem, OAuthAuthenticator.BuildUrl needs to be updated.

If you need more detail information or fixed code, please contact me.

Getting MissingManifestResourceException on WP7

Hi,

i tried to recompile the Lib and changed the resource.resx according to the new dropbox api. But every time i try to instantiate a dropbox client wihtin my wp7 app, i always get an MissingManifestResourceException. Already tried to run the "custom tool" on the resource.resx file but it didn't help.

Are there any solutions to this? Did i miss something?

Thanks and kind regards

Kornelis

Cannot get MetaData on Windows Phone

When i try to use method GetMetaDataAsync on WP7, i receive error:

DropBoxException.Response.Content = "{"error": "Access token not found."}"

Windows Phone assembly doesn't have synchronous method GetMetaData

Any workaround exists?

Upload file broken.

I was unable to upload a file to DropBox using DropNet. At first I thought it was something I did until I re-unzipped the entire library again and ran the included Unit tests. All tests passed except Can_Upload_File.

Since I am developing a WP7 app, I tried another library, http://dropboxy.codeplex.com/. DropBoxy's upload worked, but tracing through it step-by-step, it appears identical to DropNet.

I updated DropNet's reference to RestSharp to the version included with DropBoxy and now I can upload files with DropNet. I haven't done enough examination to know what is different in DropBoxy's customized RestSharp. Neither DropNet nor DropBoxy use the latest version of RestSharp.

GetMetaDataAsync return Null metadata

Hi. Here is my code:

private void LoadContents()
        {
         App.dropNetClient = new DropNetClient("API KEY", "API SECRET", GlobalSettings.DropBoxToken, GlobalSettings.DropBoxSecret);
         App.dropNetClient.GetMetaDataAsync("/", (response) =>
                {
                    _model.Meta = response;

                },
                (error) =>
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show(error.Message);
                    });
                });
        }

But (response) always is null. I found same problem in old issues:

#8

but empty string instead "/" is not working too. Also I can't get metadata of any subfolder.

DropBox account type is Full Dropbox

UploadFile fails silently, no file copied

I tried your unit test code also--I copied it to my project.
"uploaded" is returned, non-null, so it passes your unit tests. But no file is copied to Dropbox. Same with UploadFilePut.
Yet the async versions work just fine.
Occurs with ver 1.8.3 to 1.9.1.0
Haven't tried 9.1 yet.

.GetFile() not retrieving file data but meta data

Hi,

i am using .GetFile() to download a file. But the result is looking to be the metadata instead of the actual file data.

My exact call is:
byte[] buffer = this.client.GetFile("/xxxx/xxx/xxx/xxxxxxxx.tga");

If i save this to a file the content is this (added line breaks):
{
"revision": 210,
"thumb_exists": false,
"bytes": 558392,
"modified":
"Tue, 12 Apr 2011 14:56:59 +0000",
"path": "/xxxx/xxx/xxx/xxxxxxxx.tga",
"is_dir": false,
"icon": "page_white",
"root": "dropbox",
"mime_type": "application/octet-stream",
"size": "545.3KB"
}

Am i doing something wrong or is it a bug?

--Daniel

MetaData Modified var defined as DateTime, should be String

I might be wrong about this, but based on my experiments I noticed that when requesting metadata for a folder or file, the Modified value remains on DateTime.min instead of getting the real file/folder modification date, as shown in DB.

It seems that the Modified var within the MetaData class should be defined as String and not DateTime, since the conversion to DateTime isn't handled automatically. You should first read this as String and then perform your own string manipulation to extract the DateTime modification value - if needed.

Hope this helps :]

OAuth signature should be UrlEncoded

The oauth_signature parameter should also be url-encoded, since it can contain + or other special characters.

Since this file only exists in your fork of RestSharp which has no separate issue tracker, I think this issue belongs here?

GetTokenAsync fails when using NuGet package

Hi,
Calling DropNetClient.GetTokenAsync throws DropboxException ("{"error": "Bad oauth_signature for oauth_signature_method 'PLAINTEXT'"}"). I am using latest 1.9.1 NuGet package for WP7 Mango.

However, if I build DropNet from sources myself, it works and returns a valid result.

Authentication issue

I've been trying to get some basic code working to just login, it doesn't seem to want to authenticate.

    DropNetClient c = new DropNetClient("API_KEY", "API_SECRET");
    var ul = c.Login("xxx", "xxx");

    if (ul == null)
        Debug.Log("ul is null");

    if (!string.IsNullOrEmpty(ul.Token))
    {
        Debug.Log("Authenticated.");
    }
    else
    {
        Debug.Log("Authentication failed.");
    }

ul always turns out to be null. This is in a Mono environment in Unity3.3

I also tried compiling and running the DropNet.CLI in .NET Visual C# Studio 2008. Tried uploading a file and it wouldn't authenticate there either. I have no trouble logging into my dropbox account using the normal Dropbox desktop client for Windows.

Async login doesn't work

When i try to use LoginAsync i cannot login successfully, instead get error:

error.ErrorMessage = "Value cannot be null.\r\nParameter name: s"

Same parameters with sync function Login works well.

Tested v1.5.5 on Windows

DropNet MetaData

I had to change the Modified field on the DropNet.Models.MetaData class to use the string DataType because I kept getting the DateTime.Min value returned.

Oddly enough the string returned can be parsed into a DateTime after it is retrieved from the Response.

Problem with CreateFolder

Hi,

i made a test in WP7 with DropNet. In the code below i login to the DropBox with
the DropClient, which is working without problems. After that i would create a folder with CreateFolder, but
each time the function ShowFailure is started.
Has anyone an idea, why?

public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
DropNetClient dc;
Action<DropNet.Models.MetaData> suc;
Action<DropNet.Exceptions.DropboxException> fail;

        suc = delegate(DropNet.Models.MetaData m) {ShowMetadata(m);};
        fail = delegate(DropNet.Exceptions.DropboxException f) { ShowFailure(f); };
        dc = new DropNetClient("xxxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyyyyyyy","xxxxxxxx","yyyyy");
        dc.CreateFolder("/test",suc,fail);

    }
    private static void ShowMetadata(DropNet.Models.MetaData meta)
    {
        MessageBox.Show(meta.Path);
    }
    private static void ShowFailure(DropNet.Exceptions.DropboxException fail)
    {
        MessageBox.Show(fail.Message);
    }
}

rg
elu

Get Public Link

Is it possible to add an option to get the public link of a file in the public foler?

Login not working anymore - Protocol Changed by Dropbox ?

Hello,

currently i can't connect to dropbox anymore. It seems like they changed the protocol once again. Do you have any ideas?

Regards

Kevin

Here is a simple Stacktrace:

System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinst
anz festgelegt.
bei RestSharp.RestClient.GetHandler(String contentType)
bei RestSharp.RestClient.Deserialize[T](RestRequest request, RestResponse raw)
bei RestSharp.RestClient.Execute[T](RestRequest request)
bei DropNet.DropNetClient.Login(String email, String password)
bei DropSync.Program.CreateRequest()
bei DropSync.Program.Main(String[] args)

No licence info?

Maybe I'm just slow, but I can't find any licence info for this project. I'm keen on making use of DropNet, but need to know if it's GPL/MIT/Apache

Root directory

I attempted to use the following (VS 2008):

  //test
  DropNetClient client = new DropNetClient("myvalidkey", "myvalidsecret");
  client.Login("memsom@validemailaddress", "validpassword");
  var result = client.GetMetaData("/");

  StringBuilder sb = new StringBuilder();
  foreach (var item in result.Contents)
  {
    sb.Append(item.Name);
  }

  textBox1.Text = sb.ToString();

However, I get nothing returned in the "result". If I do the exact same code, but I use a sub directory name (i.e. instead of "/" I pass "/validdirectoryname"), I get the metadata for that directory. Either I'm doing something wrong, Dropbox have an issue/do not allow root access or "something".

I literally only just set up the App key, and it's not "production". Might that be the issue?

Synchronous file upload is using wrong restClient

In DropNet / Client / Files.Sync.cs in method UpladFile _restClient is used while _restClientContent should have been used. Additionally after the upload fails no exception gets thrown or anything of the sorts to indicate that there was a failure.

Update RestSharp to 102.x

Since RestSharp 102.x doesn't work with DropNet anymore we need to make it work (So we can get it from NuGet)

Downloading Large File

Hi,

I'm trying to use DropNet to download a large file (~300MB) and I'm running into an OutOfMemory exception. My guess is that the RestResponse is accumulating the file internally. Would it be possible to have a callback so that I can write the file to disk in chunks?

Thanks,
idancy

UploadFile returns error with latest RestSharp

Hi there

I'm trying to use the current RestSharp, and while I can get meta data and other stuff, I can't Upload a file. I get this back:

{"error": {"file": "Expecting a file upload"}}

The uploaded packet looks like this:

POST /1/files/dropbox/ HTTP/1.1
Accept:
User-Agent: RestSharp 102.7.0.0
Content-Type: multipart/form-data; boundary=-----------------------------28947758029299
Content-Length: 1161
Connection: keep-alive
Host: api-content.dropbox.com
Accept-Encoding: gzip, deflate

-------------------------------28947758029299
Content-Disposition: form-data; name="file"

test.txt
-------------------------------28947758029299
Content-Disposition: form-data; name="oauth_consumer_key"

x89v5xxxxhsyy35
-------------------------------28947758029299
Content-Disposition: form-data; name="oauth_nonce"

2592846
-------------------------------28947758029299
Content-Disposition: form-data; name="oauth_signature_method"

PLAINTEXT
-------------------------------28947758029299
Content-Disposition: form-data; name="oauth_timestamp"

1335108530
-------------------------------28947758029299
Content-Disposition: form-data; name="oauth_token"

9sxsxxxxxxxxsqyl
-------------------------------28947758029299
Content-Disposition: form-data; name="oauth_version"

1.0
-------------------------------28947758029299
Content-Disposition: form-data; name="oauth_signature"

jjqx2vxxx7qfbho&9pqg4gxxxxtquxy
-------------------------------28947758029299
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: application/octet-stream

hello world

-------------------------------28947758029299--

(it's a small hello world file).

Any ideas? I can't find anything in google on what the error means.

Problem with registration on WP7

Hello!
I've got a trouble with user registration using dropnet.
You can see exception here: http://dl.dropbox.com/u/6303250/exception.png
In this way I'm trying make registration:

RegClient = new DropNetClient("key", "secret");

RegClient.CreateAccountAsync(EmailBox.Text, FNameBox.Text, LNameBox.Text, PasswordBox.Password, (response) =>
{
MessageBox.Show("Excellent! Now you will be automatically signed in your account.");
},
(error) =>
{
MessageBox.Show("Enter a valid information");
});

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.