POST以获取Trustpilot API访问令牌挑战

时间:2015-01-18 00:36:25

标签: json vbscript asp-classic oauth-2.0 msxml

我有以下脚本似乎没问题,但它返回以下

  

{“reason”:“Unknown grant_type”}

http://apps.trustpilot.com/authentication

我使用了一个公共函数来生成Base 64编码,它似乎按照下面提到的response.write工作。从引用的文档链接,你看到我可能缺少什么?我相信我有正确的密钥,密码,用户名和密码。我是否正确处理了授权类型的有效负载?

这是VBScript代码:

<%
Dim consumerKey,consumerSecret,EndPoint,Payload,myCstr,myAuth
consumerKey = "XXXX"
consumerSecret = "YYYY"
EndPoint = "https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken"
Payload = "grant_type=password&username=aaa@bbb.com&password=pass28"
myCstr = Base64_Encode(consumerKey & ":" & consumerSecret)
myAuth = "Basic "&myCstr
response.write(Endpoint & "?" & Payload & "<br>")    
response.write(myAuth)
Dim xmlhttp 
Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST",EndPoint & "?" & Payload,false    
'this code not sure if I need - xmlhttp.setRequestHeader "User-Agent","HTTP/1.1"
xmlhttp.setRequestHeader "Authorization", myAuth
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send
Response.write xmlhttp.responseText
%>

1 个答案:

答案 0 :(得分:2)

每条评论(谢谢,我是新手),这就是我如何让它发挥作用:

我最初错过了xmlhttp.responsetext,在此之前根本没有得到任何回复,想到我会在此时分享,以防其他人遇到问题,比如花了几个小时搞清楚!

<%
Dim consumerKey,consumerSecret,myCstr    
consumerKey = "XXXX"
consumerSecret = "YYYY"
EndPoint = "https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken"
Payload = "grant_type=password&username=aaa@bbb.com&password=pass28"
myCstr = Base64_Encode(consumerKey & ":" & consumerSecret)
myAuth = "Basic "&myCstr
response.write(Endpoint & "?" & Payload & "<br>")    
response.write(myAuth)
Dim xmlhttp 
Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST",EndPoint,false    
'xmlhttp.setRequestHeader "User-Agent","HTTP/1.1"
xmlhttp.setRequestHeader "Authorization", myAuth
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send(Payload)
Response.write xmlhttp.responseText
%>