首页 文章

示例onedrive winforms app vb.net

提问于
浏览
0

我一直在网上搜索一个基本的示例winforms应用程序,该应用程序是用vb.net编写的,用于将文件上传到onedrive . 有谁知道吗?

我正在尝试使用vb.net中的winforms应用程序上传文件 . 我正在让auth工作......但是调用next方法会返回401 ...

我做了以下事情:

共享范围为String = "wl.skydrive_update"共享client_id为String = "0000000040144E26"共享signInUrl为新Uri([String] .Format(“_ 374304 {0}&redirect_uri = https://login.live.com/oauth20_desktop.srf&response_type=code&scope= {1}”,client_id,范围))

Private Sub cmdOneDriveAuth_Click(sender as Object,e As EventArgs)处理cmdOneDriveAuth.Click尝试Dim auth As New FrmAuthBrowser auth.WebBrowser1.Navigate(signInUrl)auth.Show()

Catch ex As Exception

    End Try
End Sub

然后在auth窗口中:

Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    Try
        If WebBrowser1.Url.AbsoluteUri.Contains("code=") Then
            Dim AuthCode As String = System.Web.HttpUtility.ParseQueryString(WebBrowser1.Url.Query)("code")
            My.Settings.OneDrive_Enabled = True
            My.Settings.OneDrive_AuthCode = AuthCode
            My.Settings.Save()
            Me.Dispose()
        End If


    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

但是当我尝试获取根信息时,我得到了401 ...

Private Sub Button1_Click(发送者为对象,e为EventArgs)处理Button1.Click尝试Dim客户端为新WebClient()Dim result = client.OpenRead(New Uri(“https://apis.live.net/v5.0/me/skydrive?access_token=”My.Settings.OneDrive_AuthCode))Dim sr As StreamReader = New StreamReader(result)MsgBox(sr.ReadToEnd())Catch ex As Exception MsgBox(ex.ToString)End Try End Sub

任何人都可以给我一些指导吗?

1 回答

  • 0

    看起来您正在使用OAuth的“代码”流程,但您错过了一个步骤 . 您获得的“代码”与access_token不同 . 您需要先对登录服务器进行另一次调用,以便为access_token交换代码 .

    POST https://login.live.com/oauth20_token.srf
    Content-Type: application/x-www-form-urlencoded
    
    client_id={client_id}&redirect_uri={redirect_uri}&client_secret={client_secret}
    &code={code}&grant_type=authorization_code
    

    你可以在这里找到更多细节http://onedrive.github.io/auth/msa_oauth.htm#code-flow .

    OneDrive刚刚发布了一个新API,所以我鼓励你查看一下 . http://onedrive.github.io/

    还有一个示例Windows / C#应用程序,您可以查看有关如何登录和上载文件的参考 . https://github.com/OneDrive/onedrive-explorer-win

相关问题