401 System.UnauthorizedAccessException的访问时用的Dropbox API SharpBox [英] 401 System.UnauthorizedAccessException when access Dropbox With SharpBox API

查看:348
本文介绍了401 System.UnauthorizedAccessException的访问时用的Dropbox API SharpBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在code

config = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox) 
    as DropBoxConfiguration;
//config.AuthorizationCallBack = new Uri("http://localhost:61926/DBoxDemo.aspx");

requestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(config, "KEY", "SECRET");
//Session["requestToken"] = requestToken;

string AuthoriationUrl = DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(
    config, requestToken);
Process.Start(AuthoriationUrl);
accessToken = DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(
    config, "xxxxxxxxxxxxx", "xxxxxxxxxxxxx", requestToken);

CloudStorage dropBoxStorage = new CloudStorage();

var storageToken = dropBoxStorage.Open(config, accessToken);
var publicFolder = dropBoxStorage.GetFolder("/");

// upload a testfile from temp directory into public folder of DropBox
String srcFile = Environment.ExpandEnvironmentVariables(@"C:\Test\MyTestFile.txt");
var rep = dropBoxStorage.UploadFile(srcFile, publicFolder);
MessageBox.Show("Uploaded Successfully..");

**dropBoxStorage.DownloadFile("/MyTestFile.txt",
Environment.ExpandEnvironmentVariables("D:\\test"));**

MessageBox.Show("Downloaded Successfully..");
dropBoxStorage.Close();

这是在Visual Studio中所示的错误。

This is the Error shown in Visual Studio.

推荐答案

SharpBox有只发生在.NET 4.5中的错误,因为类的行为的System.Uri 已经改变了从4.0到4.5。

SharpBox has a bug that only occurs in .NET 4.5, because the behavior of the class System.Uri has changed from 4.0 to 4.5.

该方法 GetDownloadFileUrlInternal()中的 DropBoxStorageProviderService.cs 的产生不正确的URL,因为它改变了%2F 。在.NET 4.0中,这个URL将被正确回到方法转换通过的System.Uri 对象 GenerateSignedUrl() OAuthUrlGenerator.cs

The method GetDownloadFileUrlInternal() in DropBoxStorageProviderService.cs generates an incorrect URL, because it changes a slash in %2f. In .NET 4.0, this URL will be converted correctly back through the System.Uri object in the method GenerateSignedUrl() in OAuthUrlGenerator.cs.

我已经改变了方法 GetDownloadFileUrlInternal()此...

I have changed the method GetDownloadFileUrlInternal() from this...

public static String GetDownloadFileUrlInternal(IStorageProviderSession session, ICloudFileSystemEntry entry)
{
    // cast varibales
    DropBoxStorageProviderSession dropBoxSession = session as DropBoxStorageProviderSession;

    // gather information
    String rootToken = GetRootToken(dropBoxSession);
    String dropboxPath = GenericHelper.GetResourcePath(entry);

    // add all information to url;
    String url = GetUrlString(DropBoxUploadDownloadFile, session.ServiceConfiguration) + "/" + rootToken;

    if (dropboxPath.Length > 0 && dropboxPath[0] != '/')
        url += "/";

    url += HttpUtilityEx.UrlEncodeUTF8(dropboxPath);

    return url;
} 

...这个...

...to this...

public static String GetDownloadFileUrlInternal(IStorageProviderSession session, ICloudFileSystemEntry entry)
{
    // cast varibales
    DropBoxStorageProviderSession dropBoxSession = session as DropBoxStorageProviderSession;

    // gather information
    String rootToken = GetRootToken(dropBoxSession);

    // add all information to url;
    String url = GetUrlString(DropBoxUploadDownloadFile, session.ServiceConfiguration) + "/" + rootToken;

    ICloudFileSystemEntry parent = entry.Parent;
    String dropboxPath = HttpUtilityEx.UrlEncodeUTF8(entry.Name);

    while(parent != null)
    {
        dropboxPath = HttpUtilityEx.UrlEncodeUTF8(parent.Name) + "/" + dropboxPath;
        parent = parent.Parent;
    }

    if (dropboxPath.Length > 0 && dropboxPath[0] != '/')
        url += "/";

    url += dropboxPath;

    return url;
}

和它目前与.NET 4.5的作品。它可能存在更好的方法来解决这个问题,但目前没有任何不当行为的注意。

and currently it works with .NET 4.5. It may exist a better way to fix the problem, but currently no misconduct noticed.

这篇关于401 System.UnauthorizedAccessException的访问时用的Dropbox API SharpBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆