BOX Access token API V2

情到浓时终转凉″ 提交于 2020-01-06 08:11:36

问题


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 

回答1:


This is the problem

        '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)

You need to send that string as part of the POST body, not as headers.




回答2:


You may also need to add the following to ensure you're using xml encoding.

request.Method = Method.POST
request.RequestFormat = DataFormat.Xml


来源:https://stackoverflow.com/questions/14528799/box-access-token-api-v2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!