我正在尝试从 BOX.COM oauth2 检索访问令牌,无论我做什么,我都会收到相同的错误。{"error":"invalid_request","error_description":"无效的 grant_type 参数或缺少参数"}。我每次尝试都验证了客户端 ID、客户端密码并获得了一个新代码(每 30 秒过期一次)。我已经尝试过 VB.NET、C# 甚至是 FireFox 的 RestClient 插件。下面是我正在使用的 VB.NET 代码。任何帮助将不胜感激!谢谢,布赖恩
Public Sub GetAccessToken(ByVal code As String, ByVal client_id As String, ByVal client_secret As String)
Dim xrc As RestClient = New RestClient
Dim grant_type As String = "authorization_code"
Dim request As New RestRequest(Method.POST)
Dim strHeaders As String
Dim response As RestResponse
Dim strResponse As String
Try
'Base URL
xrc.BaseUrl = "https://api.box.com"
'Resource
request.Resource = "oauth2/token"
'Format Headers
strHeaders = String.Format("grant_type={0}&code={1}&client_id={2}&client_secret={3}", grant_type, code, client_id, client_secret)
'Add Headers to request
request.AddHeader("Authorization", strHeaders)
'Execute
response = xrc.Execute(request)
'Parse Response
strResponse = response.Content
Catch ex As Exception
End Try
End Sub