使用DropBox的Asp.Net应用程序无法正常工作

时间:2015-12-15 15:17:56

标签: asp.net vb.net dropbox dropbox-api

我设置了DropBox应用程序类型Full DropBox;我在我的应用程序中设置了以下功能:

Private Const AppKey As String = "my key"
Private Const AppSecret As String = "my secret"
Private Function Upload() As String
Dim client As DropNetClient
Dim token As UserLogin
Dim userToken As String = My.Settings.userToken
Dim userSecret As String = My.Settings.userSecret
Dim needAccessToken As Boolean = (String.IsNullOrEmpty(userToken) Or String.IsNullOrEmpty(userSecret))
If (needAccessToken) Then
    client = New DropNet.DropNetClient(AppKey, AppSecret)
    client.UseSandbox = True
    client.GetToken()
    Dim url = client.BuildAuthorizeUrl()
    Try
        token = client.GetAccessToken()
    Catch ex As Exception
        Console.WriteLine("Exception! " + ex.Message)
        Exit Function
    End Try
    userToken = token.Token
    userSecret = token.Secret
    My.Settings.Properties.Item("userToken").DefaultValue = userToken
    My.Settings.Properties.Item("userSecret").DefaultValue = userSecret
    My.Settings.Save()
Else
    client = New DropNet.DropNetClient(AppKey, AppSecret, userToken, userSecret)
    client.UseSandbox = True
End If
Dim rawData As Byte() = File.ReadAllBytes(Server.MapPath("") + "/Fax/" + "Fax.zip")
Dim result As MetaData = client.UploadFile("/", "fax.zip", rawData)

End Function

不幸的是,教育tokens = GetAccessToken ()我收到错误:

  

收到回复[未经授权]:预计会看到[确定]。 HTTP响应是[{“”错误“”:“”请求令牌未经用户正确授权。 “”}]“。

我检查了网址(client.BuildAuthorizedUrl ())并将其返回“未经授权”。

如何链接到Dropbox文件夹?我做错了什么?或者我是否需要设置更好的Dropbox应用程序?

1 个答案:

答案 0 :(得分:0)

通过BuildAuthorizeUrl获取网址后,您需要将用户发送到该地址并让他们授权您的应用。只有在他们完成后才能拨打GetAccessToken

您看到的错误是因为您在用户实际授权您的应用之前尝试获取访问令牌。