I am trying to retrieve an Access Token from BOX.COM oauth2 and no matter what I do I get the same error. {"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"}. I have verified the client id, client secret and get a new code every time I try (the expire every 30 seconds). I have tried VB.NET, C# and even the RestClient plugin for FireFox. Below is the VB.NET code that I am using. Any help would be greatly appreciated! Thanks, Brian
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
You may also need to add the following to ensure you're using xml encoding.
This is the problem
You need to send that string as part of the POST body, not as headers.