Java 具有scribe库的Box OAuth2 API上缺少无效的grant_类型参数或参数

Java 具有scribe库的Box OAuth2 API上缺少无效的grant_类型参数或参数,java,oauth-2.0,jenkins-plugins,box-api,scribe,Java,Oauth 2.0,Jenkins Plugins,Box Api,Scribe,我正在尝试编写一个简单的Jenkins插件,该插件与Box集成,但我总是遇到以下错误: === Box's OAuth Workflow === Fetching the Authorization URL... Got the Authorization URL! Now go and authorize Scribe here: https://www.box.com/api/oauth2/authorize?client_id=abc123&redirect_uri=http%3

我正在尝试编写一个简单的Jenkins插件,该插件与Box集成,但我总是遇到以下错误:

=== Box's OAuth Workflow ===

Fetching the Authorization URL...
Got the Authorization URL!
Now go and authorize Scribe here:
https://www.box.com/api/oauth2/authorize?client_id=abc123&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fjenkins%2Fconfigure&response_type=code&state=authenticated
And paste the authorization code here
>>xyz9876543

Trading the Request Token for an Access Token...
Exception in thread "main" org.scribe.exceptions.OAuthException: Cannot extract an acces token. Response was: {"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"}
    at org.scribe.extractors.JsonTokenExtractor.extract(JsonTokenExtractor.java:23)
    at org.scribe.oauth.OAuth20ServiceImpl.getAccessToken(OAuth20ServiceImpl.java:37)
    at com.example.box.oauth2.Box2.main(Box2.java:40)
Box2类(用于测试):

BoxApi等级:

public class BoxApi extends DefaultApi20 {
    private static final String AUTHORIZATION_URL =
            "https://www.box.com/api/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code&state=authenticated";

    @Override
    public String getAccessTokenEndpoint() {
        return "https://www.box.com/api/oauth2/token?grant_type=authorization_code";        
    }


    @Override
    public String getAuthorizationUrl(OAuthConfig config) {
        return String.format(AUTHORIZATION_URL, config.getApiKey(),
                OAuthEncoder.encode(config.getCallback()));
    }

    @Override
    public Verb getAccessTokenVerb(){
       return Verb.POST;
    }

    @Override
    public AccessTokenExtractor getAccessTokenExtractor() {
        return new JsonTokenExtractor();
    }
}

我不知道我是怎么得到这些例外的。知道Box API的人能告诉我我是否做了什么错误吗?

访问令牌的请求需要采用POST请求的形式,在请求正文中包含参数的情况下–看起来您正在发送一个GET,其中的参数作为URL参数。

所有请求都必须是post?添加了post动词,但仍然失败。您是否解决过此问题?即使正在传递
grant\u type=authorization\u code
,我也有同样的问题。请检查John Hoerr回复:
public class BoxApi extends DefaultApi20 {
    private static final String AUTHORIZATION_URL =
            "https://www.box.com/api/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code&state=authenticated";

    @Override
    public String getAccessTokenEndpoint() {
        return "https://www.box.com/api/oauth2/token?grant_type=authorization_code";        
    }


    @Override
    public String getAuthorizationUrl(OAuthConfig config) {
        return String.format(AUTHORIZATION_URL, config.getApiKey(),
                OAuthEncoder.encode(config.getCallback()));
    }

    @Override
    public Verb getAccessTokenVerb(){
       return Verb.POST;
    }

    @Override
    public AccessTokenExtractor getAccessTokenExtractor() {
        return new JsonTokenExtractor();
    }
}