大家好我正在尝试使用scribe-java库通过http.code访问REST api看起来
.annotate()
引发以下错误 {“errors”:[{“code”:“woocommerce_api_authentication_error”,“message”:“oauth_consumer_key参数丢失”}]} 。任何想法为什么我的代码抛出上述错误?请注意,我已经使用http检查了v1端点,并且它返回了合理的消息。所以基本上它正在工作。
答案 0 :(得分:2)
删除'&'来自https://github.com/fernandezpablo85/scribe-java/blob/master/src/main/java/org/scribe/services/HMACSha1SignatureService.java#L32的+ OAuthEncoder.encode(tokenSecret),并将签名类型添加并更改为QueryString,现在可以正常工作。
清洁后我会提出PR。谢谢Pablo。以下是完整的代码
package org.scribe.builder.api;
import org.scribe.model.Token;
import org.scribe.model.Verb;
public class OneLeggedApi10 extends DefaultApi10a {
@Override
public String getAccessTokenEndpoint() {
return null;
}
@Override
public String getRequestTokenEndpoint() {
return null;
}
@Override
public String getAuthorizationUrl(Token requestToken) {
return null;
}
@Override
public Verb getAccessTokenVerb() {
return Verb.GET;
}
@Override
public Verb getRequestTokenVerb() {
return Verb.GET;
}
}
示例类
package org.scribe.examples;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class WooCommerceOauth1Example {
private static final String NETWORK_NAME = "Woocommerce";
private static final String RESOURCE_URL = "http://YOUR_DOMAIN/wc-api/v1/orders/count";
private static final String SCOPE = "*"; //all permissions
public static void main(String[] args) {
OAuthService service = new ServiceBuilder().provider(OneLeggedApi10.class)
.apiKey("API_KEY")
.apiSecret("SECRET_KEY")
.debugStream(System.out)
.signatureType(SignatureType.QueryString)
/*.scope(SCOPE).*/
.build();
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, RESOURCE_URL);
service.signRequest(new Token("", ""), request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}