【问题标题】:VBA to SmartSheet APIVBA 到 SmartSheet API
【发布时间】:2019-02-21 21:39:24
【问题描述】:
Public Function GETSHEET(sID As String, xTOK As String) As WebResponse


Dim sSHEET As New WebClient
Dim xD As New Dictionary
Dim xR As WebResponse
Dim xNC As New Collection

sSHEET.BaseUrl = "https://api.smartsheet.com/2.0/sheets/"

Set xR = sSHEET.GetJson(sID)
xNC.Add WebHelpers.CreateKeyValue("Authorization", "Bearer " & xTOK)
xD.Add "Headers", Headers
Set xR = sSHEET.GetJson(sID, xD)

If xR.StatusCode = WebStatusCode.Ok Then
    Set GETSHEET = xR
Else
    bR = MsgBox("Error!" & Chr(10) & _
                        "Status Code : " & xR.StatusCode & Chr(10) & _
                        "Code Description : " & xR.StatusDescription & Chr(10) & _
                        "Content : " & xR.Content, vbCritical, "Error!")

    Debug.Print "Error!"
    Debug.Print xR.StatusCode
    Debug.Print xR.StatusDescription
    Debug.Print xR.Content
    End
End If

End Function

所以,我得到了响应状态代码:404 错误代码:1006 - 未找到,但令牌正常,并且在函数中给出了工作表的 ID。为什么找不到工作表?

【问题讨论】:

  • 您正在使用哪个附加库,其中一个成员具有 .GetJson 等方法?
  • vba-web by TimhallL github.com/VBA-tools/VBA-Web
  • 啊,是的。很久以前玩过。
  • @QHarr,我做错了什么?
  • 您是否尝试过使用 Postman 之类的工具进行测试?恐怕我无法真正帮助解决这个问题,因为我没有帐户,也不确定预期的最终结果是什么。

标签: json excel vba api get


【解决方案1】:

@QHarr,我刚刚尝试了不同的方法。实际上要容易得多。谢谢你的帮助!

Public Sub IMPORTMESTER()

Dim username As String, APIkey As String
Dim URL As String
Dim httpReq As Object


xTOK = "bdj62bzknriy3dd9g561on2xl2"

URL = "https://api.smartsheet.com/2.0/sheets/7352150637471620"

Set httpReq = CreateObject("MSXML2.XMLHTTP.6.0")
With httpReq
    .Open "GET", URL, False
    .setRequestHeader "Authorization", "Bearer " & xTOK
    .send
    MsgBox "Status = " & .statustext & vbNewLine & _
           "Response = " & .responseText
End With

End Sub

【讨论】:

    猜你喜欢
    • 2022-08-23
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多