0
请原谅我,如果我问一些愚蠢的东西,我是一个新手在这里。我需要在我的Java应用程序中实施OAuth以对launchpad.net API进行身份验证。 documentation指定使用三个参数启动令牌请求:oauth_consumer_key例如(我的应用程序的名称),oauth_signature_method例如“PLAINTEXT”和oauth_signature,例如字符串“&”。我意识到大多数OAuth库要求我已经从OAuth提供者(例如Twitter发布的)中获得了消费者密钥和消费者ID /密钥,并且大多数示例都以这种方式组织。但是,launchpad.net只有在发出请求令牌(他们不使用第三方提供者)之后才会发出这些参数。我该如何继续?我现在在尝试一些引发错误的库后仍然陷入困境。非常感谢任何有用的信息。正式的launchpad库在python中。Oauth令牌请求提供者凭据发布前
我最初的代码如下:
public class Quicky {
public static void main(String[] args) throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
HttpGet httpGet = new HttpGet("https://launchpad.net/+request-token");
CloseableHttpResponse response1 = httpclient.execute(httpGet);
try {
System.out.println("Your current GET request status:" + response1.getStatusLine());
HttpEntity entity1 = response1.getEntity();
EntityUtils.consume(entity1);
} finally {
response1.close();
}
HttpRequest request;
HttpPost httpPost = new HttpPost("https://launchpad.net/+request-token");
PostMethod poster = new PostMethod();
List <NameValuePair> postParams = new ArrayList <NameValuePair>();
postParams.add(new BasicNameValuePair("oauth_customer_key", "XXXX"));
postParams.add(new BasicNameValuePair("oauth_signature_method", "PLAINTEXT"));
postParams.add(new BasicNameValuePair("oauth_signature", "&"));
httpPost.setEntity(new UrlEncodedFormEntity(postParams, "utf-8"));
// httpPost.setEntity(entity1);
httpclient.execute(httpPost);
HttpParameters requestParams = (HttpParameters) postParams;
CloseableHttpResponse response2 = httpclient.execute(httpPost);
try {
System.out.println("Your current POST request status:" + response2.getStatusLine());
HttpEntity entity2 = response2.getEntity();
// do something useful with the response body
// and ensure it is fully consumed
EntityUtils.consume(entity2);
} finally {
response2.close();
}
} finally {
httpclient.close();
}
}
}
显示你到目前为止所尝试过的,并具体。你有一个合理的问题,但它可能会被关闭,因为你没有提供足够的信息。 –
@MadPhysicist感谢您的有用观察。我已经添加了我的代码。我跑步时会得到401。 – SyCode