Java 正在使用OAuth 1.0请求Twitter api

Java 正在使用OAuth 1.0请求Twitter api,java,spring-boot,twitter,twitter-oauth,Java,Spring Boot,Twitter,Twitter Oauth,我正在尝试使用Twitter的好友列表api,并且在没有任何参数的情况下成功地做到了这一点 但是,每当我添加一个参数时,就会出现错误“无法验证您的身份”。当朋友列表太长时,我别无选择,只能添加一个游标参数 当我在没有任何参数的情况下调用api时,我会得到一个朋友的用户列表,这一事实使我认为对请求进行身份验证工作正常 我已尝试更改导致身份验证错误的请求url 我尝试使用和来制作oauth_签名,但他们都失败了 我尝试使用不同的参数,如屏幕名称或用户id,它们都会给我相同的错误 我甚至尝试像POST

我正在尝试使用Twitter的好友列表api,并且在没有任何参数的情况下成功地做到了这一点

但是,每当我添加一个参数时,就会出现错误“无法验证您的身份”。当朋友列表太长时,我别无选择,只能添加一个
游标
参数

当我在没有任何参数的情况下调用api时,我会得到一个朋友的用户列表,这一事实使我认为对请求进行身份验证工作正常

我已尝试更改导致身份验证错误的请求url

我尝试使用和来制作oauth_签名,但他们都失败了

我尝试使用不同的参数,如屏幕名称或用户id,它们都会给我相同的错误

我甚至尝试像POST请求一样添加
游标:-1
标题,但也没有成功

现在我的代码是这样的

public String getFriendList() {
    String baseUrl = "https://api.twitter.com/1.1/friends/list.json";

    // Creates a map with all necessary headers
    Map<String, String> headers = createMap(); 
    headers.put("oauth_token", <OAuth token of user>);
    String signature = createSignature("GET", baseUrl, headers, <OAuth secret of user>);

    // Add oauth_signature to header
    headers.put("oauth_signature", signature);

    String body = sendGetRequest(baseUrl, headers);
    return body;
}

public String sendGetRequest(String baseUrl, Map<String, String> parameters) throws AuthException, IOException {
    try (CloseableHttpClient client = CloseableHttpClientFactory.getHttpClient()) {
        HttpGet httpGet = new HttpGet(baseUrl);

        if (parameters != null) {
            httpGet.setHeader("Authorization", createHeader(parameters));
        }

        CloseableHttpResponse response = client.execute(httpGet);

        if (response.getStatusLine().getStatusCode() != 200) {
            LOGGER.info("GET Request Failed : " + EntityUtils.toString(response.getEntity()));
            throw new Exception();
        }

        String responseBody = EntityUtils.toString(response.getEntity());
        return responseBody;
    }
}
公共字符串getFriendList(){
字符串baseUrl=”https://api.twitter.com/1.1/friends/list.json";
//创建包含所有必要标题的映射
Map headers=createMap();
headers.put(“oauth_令牌”);
stringsignature=createSignature(“GET”,baseUrl,headers,);
//将oauth_签名添加到标头
标题。放置(“oauth_签名”,签名);
String body=sendGetRequest(baseUrl、头);
返回体;
}
公共字符串sendGetRequest(字符串baseUrl、映射参数)引发AuthException、IOException{
try(CloseableHttpClient-client=CloseableHttpClientFactory.getHttpClient()){
HttpGet-HttpGet=新的HttpGet(baseUrl);
if(参数!=null){
setHeader(“授权”,createHeader(参数));
}
CloseableHttpResponse response=client.execute(httpGet);
如果(response.getStatusLine().getStatusCode()!=200){
info(“获取请求失败:+EntityUtils.toString(response.getEntity()));
抛出新异常();
}
String ResponseBy=EntityUtils.toString(response.getEntity());
返回响应体;
}
}
这是工作代码

谁能告诉我在哪里添加参数以及我错过了什么来验证请求


编辑:添加了sendGetRequest的代码。制作签名并添加标题是根据twitter上的文档制作的

您是否使用库来创建授权标题?如果没有,则需要手动创建此项,而不是按照我在方法
sendGetRequest
中创建授权标头的顺序对参数进行排序。此外,我还在参数头上使用树形图,以便对其进行排序。这有帮助吗?您是否使用库来创建授权标头?如果没有,则需要手动创建此项,而不是按照我在方法
sendGetRequest
中创建授权标头的顺序对参数进行排序。此外,我还在参数头上使用树形图,以便对其进行排序。这有帮助吗?