0

I am trying to use HighLabo for dropbox communications. But it is giving an error. Here is my code

    private const string App_key = "my_app_key";
    private const string App_secret = "my_app_secret";
    OAuthClient ocl = null;
    HigLabo.Net.AuthorizeInfo ai = null;

    public void UploadFile(byte[] content, string filename, string target)
    {

        ocl = DropboxClient.CreateOAuthClient(App_key, App_secret);
        ai = ocl.GetAuthorizeInfo();
        string RequestToken = ai.RequestToken;
        string RequestTokenSecret = ai.RequestTokenSecret;
        string redirect_url = ai.AuthorizeUrl;
        AccessTokenInfo t = ocl.GetAccessToken(RequestToken, RequestTokenSecret);
        string Token = t.Token;
        string TokenSecret = t.TokenSecret;

        DropboxClient cl = new DropboxClient(App_key, App_secret, Token, TokenSecret);

        HigLabo.Net.Dropbox.UploadFileCommand ul = new HigLabo.Net.Dropbox.UploadFileCommand();
        ul.Root = RootFolder.Sandbox;
        ul.FolderPath = target;
        ul.FileName = filename;
        ul.LoadFileData(content);

        Metadata md = cl.UploadFile(ul);
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        //string filename = Path.GetFullPath(FileUpload1.FileBytes);
        //byte[] bytes = System.IO.File.ReadAllBytes(filename); 
        UploadFile(FileUpload1.FileBytes, "sundas.jpg", "/Apps/synch/");   
    }

I am getting value can not be null error on

ai = ocl.GetAuthorizeInfo();

line. Does anyone know this problem?

Also i tried using Nemiro and Dropnet libraries. In Nemiro i can use with winforms. But neither nemiro nor dropnet is hard for webforms. I have to fix this problem.

2
  • Try to instantiate HigLabo.Net.AuthorizeInfo if it is a non-static class
    – Oluwafemi
    Commented Jul 18, 2016 at 8:57
  • @Oluwafemi where can i use HigLabo.Net.AuthorizeInfo. I can not use on top using HigLabo.Net.AuthorizeInfo. it is not a dll or namespace.
    – Ender Aric
    Commented Jul 18, 2016 at 9:02

2 Answers 2

1

Nemiro.OAuth was created in the first place for ASP.NET (WebForms, MVC).

The following link you can find example for Dropbox and WebForms: https://github.com/alekseynemiro/nemiro.oauth.dll/tree/master/examples/DropBoxWebForms

After the authorization of a user, you should save an access token.

Typically, save access token to database. The examples use the Session. But the Session is not a good place to store the access token.

If you save the access token to database, or at least a text file, you can use it to query, without re-authorization.

I think you have the same problems with HighLabo. You need to save an access token after authentication, and use it for all requests to the API.

3
  • Thank you. I asked you already with your website. now i downloaded your dll and examples. so it is working fine.
    – Ender Aric
    Commented Jul 18, 2016 at 13:02
  • @AlekseyNemiro How can i change the default directory from Apps/Box with a surprise to something else Commented Aug 10, 2016 at 10:21
  • 1
    @RajanGoswami, this is done in the application settings on the Dropbox website. Register your own application on the Dropbox website and you will be able to set it up. Use the obtained ID and secret key for API. Sorry for late answer. I did not see notice. Commented Aug 23, 2016 at 13:49
0

I fixed my problem with Nemiro.OAuth. The following example is very helpful.

https://github.com/alekseynemiro/nemiro.oauth.dll/tree/master/examples/DropBoxWebForms

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.