Ms Access VBA与SignNow API集成

问题描述

我有一个沙箱帐户,可以在signNow上测试API。 我会逐步测试API,以确保可以使用Access VBA进行集成。

我能够使用以下代码获取访问令牌:

   Private Sub Command5_Click()
 sUrl = "https://api-eval.signNow.com/oauth2/token"
    sUsername = "rami_jebara@hotmail.com"
    sPassword = "XXXXXXXX"
    AsToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    sgrant_type = "password"
    sscope = "*"
    sbody = "username=" & sUsername & "&password=" & sPassword & "&grant_type=" & sgrant_type & "&scope=" & sscope

    ' Make the request
    With CreateObject("MSXML2.XMLHTTP.6.0")
        .Open "Post",sUrl,False
        .SetRequestHeader "Authorization","basic " & AsToken
        .SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
        .Send sbody
        Debug.Print .responseText
        Debug.Print .GetAllResponseHeaders
        TempVars.Add "ACToken",.responseText
        Me.Requery
        Text0.Requery
    End With
End Sub

我成功授予了访问令牌

但是现在我陷入了从Access女士向SignNow上传PDF文件的问题 下面的代码是我使用的

 Option Compare Database

Private Function GetFileSize(fileFullPath As String) As Long

    Dim lngFSize As Long,lngDSize As Long
    Dim oFO As Object,OFS As Object

    lngFSize = 0
    Set OFS = CreateObject("Scripting.FileSystemObject")

    If OFS.FileExists(fileFullPath) Then
        Set oFO = OFS.getFile(fileFullPath)
        GetFileSize = 31812
    Else
        GetFileSize = 0
    End If

    Set oFO = nothing
    Set OFS = nothing
End Function
Private Function ReadBinary(strFilePath As String)
    Dim ado As Object,bytFile
    Set ado = CreateObject("ADODB.Stream")
    ado.Type = 1
    ado.Open
    ado.LoadFromFile strFilePath
    bytFile = ado.Read
    ado.Close

    ReadBinary = bytFile

    Set ado = nothing
End Function


Private Function toArray(str)
    Dim ado As Object
     Set ado = CreateObject("ADODB.Stream")
     ado.Type = 2
     ado.Charset = "_autodetect"
     ado.Open
     ado.WriteText (str)
     ado.Position = 0
     ado.Type = 1
     toArray = ado.Read()
     Set ado = nothing
End Function


Function POST_multipart_form_data(filePath As String)

    Dim oFields As Object,ado As Object
    Dim sBoundary As String,sPayLoad As String
    Dim fileType As String,fileExtn As String,fileName As String
    Dim sName As Variant

    fileName = Right(filePath,Len(filePath) - InStrRev(filePath,"\"))
    fileExtn = Right(filePath,Len(fileName) - InStrRev(fileName,"."))

    Select Case fileExtn
     Case "pdf"
        fileType = "application/pdf"
     Case "jpg"
        fileType = "image/jpeg"
     Case "txt"
        fileType = "text/plain"
    End Select


    sBoundary = String(27,"-")
    sPayLoad = ""


    sPayLoad = sPayLoad & "--" & sBoundary & vbCrLf
    sPayLoad = sPayLoad & "Content-disposition: form-data; name=""file""; " & "filename=""" & fileName & """" & vbCrLf
    sPayLoad = sPayLoad & "Content-Type: " & fileType & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf



     sPayLoad = sPayLoad & "--" & sBoundary & "--"


      Set ado = CreateObject("ADODB.Stream")
      ado.Type = 1
      ado.Open
      ado.Write toArray(sPayLoad)
      ado.Write ReadBinary(filePath)
      ado.Position = 0

    With CreateObject("MSXML2.ServerXMLHTTP")
        .Open "POST","https://api-eval.signNow.com/document","bearer " & "e3c9d47d08199cf8a4baa6529c8dc3349c0f76380c3a0fecf0842ddd600711aa"
        .SetRequestHeader "Content-Type","multipart/form-data; boundary=" & sBoundary
        .Send (ado.Read())
        MsgBox .responseText
    End With

End Function

它返回此错误

  {
    "errors": [
        {
            "code": 66048,"message": "Unable to upload pdf document,pdf document headers are malformed"
        }
    ]
}

现在我已经在处理此错误已有两个星期了,我需要帮助。 在此先感谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)