Sharpbox 1.2 API

时间:2011-11-01 20:09:18

标签: c# asp.net dropbox dropbox-api sharpbox

我尝试使用新的API sharpbox 1.2。

我试过这段代码:

if (Request.UrlReferrer.ToString() == string.Empty)           
{
  DropBoxConfiguration config = DropBoxConfiguration.GetStandardConfiguration();
  config.AuthorizationCallBack = new Uri("http://localhost:60003/Default.aspx");               
  DropBoxRequestToken token = DropBoxStorageProviderTools.GetDropBoxRequestToken(config, "customerkey", "customersecret");
  string authUrl = DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(config, token);     
  Response.Redirect(authUrl);
}             
else 
{ 
  ICloudStorageAccessToken token1 = DropBoxStorageProviderTools.LoginWithMobileAPI("username", "password", "customerkey", "customersecret");           
}

但是我得到了这样的例外:

  

"尝试执行未经授权的操作"

我正在使用Asp.NET& C#

非常感谢!

1 个答案:

答案 0 :(得分:2)

Sharpbox 1.2取消了用户名/密码传递。您必须使用ICloudStorageAccessToken来获取令牌。下载中有一个独立的exe用于将您的consumerkey和consumersecret转换为令牌。

Public dropBoxStorage As CloudStorage
    dropBoxStorage = New CloudStorage()
    Dim dropBoxConfiguration As ICloudStorageConfiguration = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox)
    Dim accesstoken As ICloudStorageAccessToken = Nothing
    Dim tokenpath As String = serverpath 
    Dim fs As FileStream = File.Open(tokenpath, FileMode.Open, FileAccess.Read, FileShare.Read)
    accesstoken = dropBoxStorage.DeserializeSecurityToken(fs)
    dropBoxStorage.Open(dropBoxConfiguration, accesstoken)