我正在使用VBA在Salesforce中获得授权,然后最终希望运行Salesforce报表并将结果转储到Excel中.我已经编写了以下文件来处理授权,但是却收到unsupported_grant_type错误.到目前为止,我拥有的代码:
I am using VBA to get authorization in Salesforce and then ultimately want to run a Salesforce report and dump the results in Excel. I have written the following to handle the authorization, but I am getting an unsupported_grant_type error. The code I have so far:
Dim XMLHTTP As New MSXML2.XMLHTTP60 Dim username As String Dim password As String Dim PasswordnUsername As String Dim argumentString As String username = "myUsername" password = "myPassword" PasswordnUsername = password & ":" & username argumentString = "?grant_type=password&" & _ "client_id=abc123&" & _ "client_secret=123abc&" & _ "username=" & username & "&password=" & password MsgBox (argumentString) Set XMLHTTP = CreateObject("MSXML2.XMLHTTP.6.0") XMLHTTP.Open "POST", "mysalesforce/services/oauth2/token", False XMLHTTP.setRequestHeader "content-type", "application/x-www-form-urlencoded" XMLHTTP.setRequestHeader "Authorization", "basic " + Base64Encode(PasswordnUsername) XMLHTTP.send (argumentString) MsgBox (XMLHTTP.responseText)当我打印XMLHTTP.responseText时,这是报告unsupported_grant_type的地方.
When I print XMLHTTP.responseText, this is where the unsupported_grant_type is reported.
任何帮助将不胜感激.预先感谢.
Any help would be appreciated. Thanks in advance.
T
推荐答案您正在使用用户名密码流" . URL中的所有参数,而不显示弹出窗口,让用户直接向SF输入其凭据(理想情况下,如果存在用户交互而不是后端系统互相交谈,则应使用另一个OAuth流程,因此您的应用无法处理密码,也无法泄漏密码).
You're using "Username-password flow". All params in the URL, without displaying a popup letting user type his credentials straight to SF (ideally if there's user interaction rather than backend systems talking to each other you're supposed to use another OAuth flow so your app doesn't handle passwords, can't leak them).
故障排除:
如果您有邮递员,curl,SoapUI或类似的客户端-在直接跳到VBA之前可能会有所帮助?
If you have Postman, curl, SoapUI or any client like that - might help before jumping straight to VBA?
这对我有用(带有Content-Type: application/x-www-form-urlencoded标头)
This works for me (with Content-Type: application/x-www-form-urlencoded header)
更多推荐
不支持的赠款类型Salesforce OAUTH2
发布评论