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.
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 .
I fixed my problem with Nemiro.OAuth. The following example is very helpful.
https://github.com/alekseynemiro/nemiro.oauth.dll/tree/master/examples/DropBoxWebForms
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.