0

我希望使用 vb.net 获取我的工作管理员 teamviewer 帐户中所有设备的列表。我还希望能够使用它的设备 ID 更改给定设备的“别名”。我对API知之甚少。我找到了以下示例,但我不确定如何调整它以获取 json 响应。

而不是访问令牌,我相信我需要使用客户端 ID 和秘密 ID 以及授权码才能使用它。如果我在当前启动中运行它,我会收到 401 未经授权的错误。任何帮助,将不胜感激。

我也不知道如何使用“PUT”来更改使用设备 ID 的别名,这两个设备 ID 都将在文本框中输入。ex alias = textbox1.text 和 device_id = textbox2.text

Private Sub SurroundingSub()
Dim accessToken As String = "xxxxxxxxxxxxxxxxxxx"
Dim apiVersion As String = "v1"
Dim tvApiBaseUrl As String = "https://webapi.teamviewer.com"
Dim address As String = tvApiBaseUrl & "/api/" & apiVersion & "/devices"

Try
    Dim request As HttpWebRequest = TryCast(WebRequest.Create(address), HttpWebRequest)
    request.Headers.Add("Bearer", accessToken)
    request.Method = "GET"
    Dim webResp As WebResponse = request.GetResponse()
Catch __unusedException1__ As Exception
msgbox(__unusedException1__.ToString)
End Try
End Sub
4

1 回答 1

0

这是获取所有设备代码:

Private Sub get_teamviewer_devices()
    Dim accessToken As String = "XXXXXXXXXXXXXXXXXXXXX"
    Dim apiVersion As String = "v1"
    Dim tvApiBaseUrl As String = "https://webapi.teamviewer.com"
    Dim address As String = tvApiBaseUrl & "/api/" & apiVersion & "/devices"
    Dim result_json As String = Nothing
    Try
        Dim request As HttpWebRequest = TryCast(WebRequest.Create(address), HttpWebRequest)
        request.Headers.Add("Authorization", "Bearer " & accessToken)
        request.Method = "GET"
        Dim webResp As WebResponse = request.GetResponse()
        Using reader = New StreamReader(webResp.GetResponseStream)
            result_json = reader.ReadToEnd()
        End Using
        TextBox1.Text = result_json
    Catch __unusedException1__ As Exception
        MsgBox(__unusedException1__.ToString)
    End Try
End Sub

这是更改别名的 PUT 部分:

Public Sub change_alias(ByVal device_id As String, ByVal alias_str As String)
    Dim accessToken As String = "XXXXXXXXXXXXXXXXXXXXX"
    Dim apiVersion As String = "v1"
    Dim tvApiBaseUrl As String = "https://webapi.teamviewer.com"
    Dim address As String = tvApiBaseUrl & "/api/" & apiVersion & "/devices/" & device_id
    Dim result As String
    Dim alias_str_ As String = Chr(34) & alias_str & Chr(34)
    Try
        Dim request As HttpWebRequest = TryCast(WebRequest.Create(address), HttpWebRequest)
        request.Headers.Add("Authorization", "Bearer " & accessToken)
        request.Method = "PUT"
        request.ContentType = "application/json"
        Using requestWriter2 As New StreamWriter(request.GetRequestStream())
            requestWriter2.Write("{""Alias"" : " & alias_str_ & "}")
        End Using
        Dim webResp As WebResponse = request.GetResponse()
        Using reader = New StreamReader(webResp.GetResponseStream)
            result = reader.ReadToEnd()
        End Using
        TextBox1.Text = (result)
    Catch __unusedException1__ As Exception
        MsgBox(__unusedException1__.ToString)
    End Try
End Sub
于 2018-06-01T22:51:48.050 回答