我试图通过oauth 1.0a来对抗discogs。我正在使用此页面中的示例: http://devjay.org/?p=22#comment-979
我的DiscoGSApi10a.java看起来完全一样。我有一个属性文件和我的主类,我在搜索错误时减少了它:
public class Auth2 {
public static void main(String[] args) throws FileNotFoundException, IOException {
Properties configProps = new Properties();
configProps.load(new FileInputStream("src/main/resources/config.properties"));
String consumer_key = configProps.getProperty("consumer.key");
String consumer_secret = configProps.getProperty("consumer.secret");
String user_agent_string = configProps.getProperty("useragent.string");
// will be empty on the first run, as token is not yet provided
String config_token = configProps.getProperty("accesstoken.key", "");
String config_secret = configProps.getProperty("accesstoken.secret", "");
//this requires user interaction if no access token is found in config.properties
OAuthService service = new ServiceBuilder()
.provider(DiscoGSApi10a.class)
.apiKey(consumer_key)
.apiSecret(consumer_secret)
.debug()
.build();
Token requestToken = service.getRequestToken();
System.out.println("Token RAW: "+ requestToken.getRawResponse());
}
}
日志和错误如下:
从中获取请求令牌 https://api.discogs.com/oauth/request_token将oauth_callback设置为 oob生成签名...使用base64编码器:DatatypeConverter 基本字符串是: POST&安培; HTTPS%3A%2F%2Fapi.discogs.com%2Foauth%2Frequest_token&安培; oauth_callback%3Doob%26oauth_consumer_key%YOUR_CONSUMER_KEY%26oauth_nonce%3D1825647227%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1420357886%26oauth_version%3D1.0 签名是:WbSZr46nikDsZGzo9gSeJcP28Xk =附加额外的OAuth 参数:{oauth_callback - > oob,oauth_signature - > WbSZr46nikDsZGzo9gSeJcP28Xk =,oauth_version - > 1.0,oauth_nonce - > 1825647227,oauth_signature_method - > HMAC-SHA1,oauth_consumer_key - > IgUpkXTCBbIZNQrlXiYk,oauth_timestamp - > 1420357886}使用Http Header签名发送请求...线程“main”中的异常 org.scribe.exceptions.OAuthConnectionException:出现问题 同时创建与远程服务的连接。在 org.scribe.model.Request.send(Request.java:70)at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:59) 在 org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:40) 在 org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:45) at de.ms.discogs.auth.Auth2.main(Auth2.java:43)引起: java.net.SocketException:来自服务器的文件的意外结束 sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:772)at at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:769)at at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323) 在 java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468) 在 sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338) 在org.scribe.model.Response。(Response.java:30)at org.scribe.model.Request.doSend(Request.java:117)at org.scribe.model.Request.send(Request.java:66)... 4 more
为什么我甚至无法连接到远程服务?
关注LStrike