BOX访问令牌API V2 [英] BOX Access token API V2

查看:240
本文介绍了BOX访问令牌API V2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从BOX.COM的oauth2检索访问令牌,无论我做什么,我得到了同样的错误。 {错误:INVALID_REQUEST,ERROR_DESCRIPTION:无效的grant_type参数或参数丢失}。我已经验证了客户端ID,客户端秘密,每次我试图(每30秒到期),得到一个新的code。
我曾尝试VB.NET,C#,甚至RESTClient实现插件Firefox浏览器。下面是VB.NET code,我使用。任何帮助将大大AP preciated!
谢谢,
布赖恩

 公用Sub GetAccessToken(BYVAL code作为字符串,BYVAL CLIENT_ID作为字符串,BYVAL client_secret作为字符串)
        昏暗的XRC作为RESTClient实现=新RESTClient实现
        昏暗grant_type作为字符串=authorization_ code
        昏暗的要求作为新RestRequest(Method.POST)
        昏暗strHeaders作为字符串
        昏暗的响应作为RestResponse
        昏暗strResponse作为字符串
        尝试
            基本URL
            xrc.BaseUrl =htt​​ps://api.box.com            资源
            request.Resource =的oauth2 /令牌            格式标题
            strHeaders =的String.Format(grant_type = {0}&放大器; code = {1}&安培; CLIENT_ID = {2}&安培; client_secret = {3},grant_type,code,CLIENT_ID,client_secret)            添加页眉要求
            request.AddHeader(授权,strHeaders)            '执行
            响应= xrc.Execute(要求)            解析响应
            strResponse = response.Content        抓住EX为例外        结束Try    结束小组


解决方案

您可能还需要添加以下,以确保您使用XML编码。

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

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.

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

这篇关于BOX访问令牌API V2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆