如何在VBA中使用适用于.Net的AWS SKD?

时间:2018-09-03 21:10:43

标签: vba amazon-web-services sdk nlp

我正在尝试将AWS Comprehend NLP添加到我的VBA项目中,但是似乎不支持VBA。 AWS确实提供了.NET SDK。使该SDK中的类可用于我的VBA代码的最佳方法是什么?

这里是VBA模块的模型,该模块将一串文本传递给Comprehend并重新获得情感分析。显然,它实际上不起作用。

该模块对于在VBA中工作并希望将AWS服务添加到其工具箱的任何人都非常有用。你能帮忙吗?

Function putAWSComprehendJSON(link As String, apiKey As String, apiSecret As String, text2comp As String) As Dictionary
'link=https://Comprehend.us-east-1.amazonaws.com
Dim endpoint as String
endpoint = "/api/endpointX"
'VBA-JSON module installed from github to handle Json packing and unpacking
Dim jsonResponse As Dictionary
Dim jsonRequest As Dictionary
Set jsonRequest = New Dictionary
jsonRequest.Add key:="action", item:="detect-sentiment"
jsonRequest.Add key:="content", item:=text2comp
jsonRequest.Add key:="content-usage-code", item:="en"
jsonRequest.Add key:="region", item:="usl-east-1"
jsonRequestBody = JsonConverter.ConvertToJson(jsonRequest)
Dim web As msxml2.XMLHTTP60
Set web = New msxml2.XMLHTTP60
With web
    .Open "POST", link & endpoint, False, apiKey, apiSecret
    .setRequestHeader "cache-control", "private"
    .setRequestHeader "Cache-Control", "max-age=0"
    .setRequestHeader "Content-type", "application/json"
    .setRequestHeader "Authorization", "Basic " & EncodeBase64
    .send jsonRequestBody
End With
While .readyState 4
DoEvents
Wend
Set putAWSComprehendJSON = JsonConverter.ParseJson(web.responseText)
End Function              

0 个答案:

没有答案