6

このコードを使用して、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 をヒットした後、別のアカウント 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"}

この後、トップコードを実行しています。キーに何か問題がありますか?コードの最初の部分で機能するのはなぜですか?

4

2 に答える 2

-1

コンシューマ キーが無効です

それは何ですか? このエラーは、コンシューマ キーが無効な場合に発生します。このエラーの最も一般的な原因は、Labs アカウントからコピーされたコンシューマ キーのタイプミスです。

トラブルシューティング チェックリスト ラボ アカウントからコンシューマー キーをコピーしてアプリケーションに貼り付け、もう一度試してください。分散認証方式を使用している場合は、返された認証コードからコンシューマ キーを適切に解析していることを確認してください。 https://labs.aweber.com/docs/troubleshooting#unauthorized

于 2016-04-29T05:45:30.883 に答える