繁体   English   中英

签名无效。 预期的签名基本字符串,JAVA

[英]Invalid signature. Expected signature base string, JAVA

我们正在使用这段代码通过oAuth向aweber发送请求

long unixTime = System.currentTimeMillis() / 1000L;
OAuthRequest request1 = new OAuthRequest(Verb.GET,"https://api.aweber.com/1.0/accounts/1111/lists/1111/subscribers", service);
request1.addBodyParameter("ws.op", "create");
request1.addBodyParameter("email", "account@gmail.com");
request1.addBodyParameter("name", "ankur");
request1.addBodyParameter("oauth_token_secret", "mysecret");
request1.addBodyParameter("oauth_token", "mytoken");
request1.addBodyParameter("oauth_consumer_key", "mykey");
request1.addBodyParameter("oauth_signature_method", "HMAC-SHA1");
request1.addBodyParameter("oauth_nonce", "secret");
request1.addBodyParameter("oauth_timestamp", String.valueOf(unixTime));

service.signRequest(accessToken, request1);
Response response1 = request1.send();
// Create a reader to read Twitter's stream
BufferedReader reader1 = new BufferedReader(new InputStreamReader(response1.getStream()));

String line;
while ((line = reader1.readLine()) != null) {
    System.out.println(line);
}      

但我们正在回应这个问题

{
    "error": {
        "status": 401,
        "documentation_url": "https://labs.aweber.com/docs/troubleshooting#unauthorized",
        "message": "Invalid signature. Expected signature base string: GET%26https%3A%2F%2Fapi.aweber.com%2F1.0%2Faccounts%2F1111%2Flists%2F1111%2Fsubscribers%26oauth_consumer_key%3Dmykey%26oauth_nonce%3Dnonce%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1461676770%26oauth_token%3Dmytoken%26oauth_version%3D1.0%20https%3A%2F%2Flabs.aweber.com%2Fdocs%2Ftroubleshooting%23unauthorized",
        "type": "UnauthorizedError"
    }
}

签名无效。 预期的签名基本字符串

我检查了我的签名,同样如此。 不知道为什么它显示不同。

更新 - 1:

很多人说我的密钥和访问令牌无效,但在我的代码中,我试图击中另一个后,我会点击第一个帐户URL。

像这样

  OAuth1AccessToken  accessToken= new OAuth1AccessToken("oauth_token","oauth_token_secret","oauth_token_secret=oauth_token_secret&oauth_token=oauth_token");
  final OAuthRequest request = new OAuthRequest(Verb.GET, ACCOUNT_RESOURCE_URL, service);
  service.signRequest(accessToken, request);

  final Response response = request.send();
  System.out.println("Got it! Lets see what we found...");
  System.out.println();
  System.out.println(response.getBody());

  System.out.println();
  System.out.println("Thats it man! Go and build something awesome with AWeber and ScribeJava! :) 11111111");

这是日志

  Got it! Lets see what we found...

 {"total_size": 1, "start": 0, "entries": [{"http_etag": "\"8c4c161ee1fd3dfg596911c82e9f2feff145907dec2-ca5feee2b7fbb6febfca8af554fg1541ea960aaedb\"", "lists_collection_link": "https://api.aweber.com/1.0/accounts/xxxx/lists", "self_link": "https://api.aweber.com/1.0/accounts/xxxx", "resource_type_link": "https://api.aweber.com/1.0/#account", "id": xxxx, "integrations_collection_link": "https://api.aweber.com/1.0/accounts/xxxx/integrations"}], "resource_type_link" : "https://api.aweber.com/1.0/#accounts"}

在此之后我运行我的顶级代码,那么我的密钥有什么问题,那么为什么它的代码的第一部分工作呢?

根本原因分析: 签名无效

当您的请求的签名与我们预期的签名不匹配时,会引发此错误。 此错误的常见原因是不正确或丢失令牌密钥( either consumer, request token, or access token )或应用程序中的错误OAuth 1.0A实现。

这里access token有一个到期时间。 在到期时间之后,访问令牌将无法工作。

还有另一个限制。 将发布limits on the number of refresh tokenslimits on the number of refresh tokens ; 每个客户端/用户组合一个限制,所有客户端的每个用户另一个限制。

因此,在您的情况下,您可能已经超出了创建刷新令牌的限制。

对于解决方案,您可以按照我的另一个答案: Google Play Developer API - 查询购买代币返回无效值


要解决您的问题,您可以按照以下步骤操作:

  1. 通过登录您的实验室帐户并将使用者密钥复制并粘贴到您的应用程序中,验证您的使用者密钥是否正确。
  2. 发出新的请求令牌和/或访问令牌,然后重试。
  3. 验证您的应用程序是否正确实施了与服务器基本字符串相关的OAuth 1.0A标准。
  4. 有关更多详细信息, 请参阅RFC5849 OAuth 1.0A规范第3.4.1节

使用者密钥无效

它是什么? 当您的使用者密钥无效时,会引发此错误。 导致此错误的最常见原因是从您的实验室帐户复制的使用者密钥中的印刷错误。

故障排除核对表将您的消费者密钥从实验室帐户复制并粘贴到您的应用程序中,然后重试。 如果使用分布式身份验证方法,请确保正确地从返回的授权代码中解析出使用者密钥。 https://labs.aweber.com/docs/troubleshooting#unauthorized

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM