Scribe を使用した OAuth Vimeo 「無効な API キー」(エラー コード 100)

StackOverflow https://stackoverflow.com//questions/9705685

  •  14-12-2019
  •  | 
  •  

質問

Vimeoで認証しようとしています 筆記者. 。あまりうまくいきません。エラー コード 100 が返され続けますが、それでも認証 URL が表示され、そこにアクセスするとアクセスを許可できます。認証コードを入力して、リクエスト トークンをアクセス トークンと交換しようとすると、機能しません。私は Facebook の例を使用し、Vimeo で動作するように調整しています。ここで何をしているのかよくわかりません。私は尋ねた 先ほどの質問 含める必要があると言われました Apache Commons コーデック 私のクラスパス上で。まあ、それを環境変数に含めましたが、何も変わりませんでした。そこで、それをプロジェクトのライブラリに追加したところ、さらに一歩前進したように思えました。ここから何をすればいいのか全く分かりません。なぜこれが得られるのかわかりません。私のコードと出力は次のとおりです。

public class VimeoTest
{
  private static final String NETWORK_NAME = "Vimeo";
  private static final Token EMPTY_TOKEN = null;

  public static void main(String[] args)
  {
    // Replace these with your own api key and secret
    String apiKey = "MYAPIKEY";
    String apiSecret = "MYAPISECRET";
    OAuthService service = new ServiceBuilder()
                                  .provider(VimeoApi.class)
                                  .apiKey(apiKey)
                                  .apiSecret(apiSecret)
                                  .debug()
                                  .build();
    Scanner in = new Scanner(System.in);

    System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
    System.out.println();
    OAuthRequest orequest = new OAuthRequest(Verb.GET, "http://vimeo.com/api/rest/v2");
    orequest.addQuerystringParameter("method", "vimeo.test.null");
    Response send = orequest.send();
    System.out.println(send.getBody());

    // Obtain the Authorization URL
    System.out.println("Fetching the Authorization URL...");
    Token requestToken = service.getRequestToken();

    String authorizationUrl = service.getAuthorizationUrl(requestToken);
    System.out.println("Got the Authorization URL!");
    System.out.println("Now go and authorize Scribe here:");

    //I do NOT want to have to do this. Is there any other way I can have this authorize without going to a web browser to do this?

    System.out.println(authorizationUrl);
    System.out.println("And paste the authorization code here");
    System.out.print(">>");
    Verifier verifier = new Verifier(in.nextLine());
    System.out.println();

    // Trade the Request Token and Verfier for the Access Token
    System.out.println("Trading the Request Token for an Access Token...");
    Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);

    //****Breaks on the line above.****
    //I think it's because the orequest.send() returned a 100 error code
    //Note, EMPTY_TOKEN is declared as null, but I think that's ok. Verifier is not null.

    System.out.println("Got the Access Token!");
    System.out.println("(if your curious it looks like this: " + accessToken + " )");
    System.out.println();

出力は次のとおりです。

=== Vimeo's OAuth Workflow ===

1.0
<?xml version="1.0" encoding="utf-8"?>
<rsp generated_in="0.0033" stat="fail">
  <err code="100" expl="The API key passed was not valid" msg="Invalid API Key" />
</rsp>
Fetching the Authorization URL...
obtaining request token from http://vimeo.com/oauth/request_token
setting oauth_callback to oob
generating signature...
base string is: POST&http%3A%2F%2Fvimeo.com%2Foauth%2Frequest_token&oauth_callback%3Doob%26oauth_consumer_key%3DACONSUMERKEY%26oauth_nonce%3D2861480766%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1331941401%26oauth_version%3D1.0
signature is: 7H/C4F4rK0FYZ5oZGf76Rl8P8yQ=
appended additional OAuth parameters: { oauth_callback -> oob , oauth_signature -> 7H/C4F4rK0FYZ5oZGf76Rl8P8yQ= , oauth_version -> 1.0 , oauth_nonce -> 2861480766 , oauth_signature_method -> HMAC-SHA1 , oauth_consumer_key -> ACONSUMERKEY , oauth_timestamp -> 1331941401 }
using Http Header signature
sending request...
response status code: 200
response body: oauth_token=bf3da4ec799559c9f8b1f8bda2b8d6ee&oauth_token_secret=AOAUTHTOEKN SECRET&oauth_callback_confirmed=true
Got the Authorization URL!
Now go and authorize Scribe here:
http://vimeo.com/oauth/authorize?oauth_token=bf3da4ec799559c9f8b1f8bda2b8d6ee
And paste the authorization code here
>>unicorn-duqx0
Exception in thread "main" java.lang.NullPointerException

Trading the Request Token for an Access Token...
obtaining access token from http://vimeo.com/oauth/access_token
    at org.scribe.oauth.OAuth10aServiceImpl.getAccessToken(OAuth10aServiceImpl.java:75)
    at autouploadermodel.VimeoTest.main(VimeoTest.java:51)
Java Result: 1
BUILD SUCCESSFUL (total time: 27 seconds)

編集:.debug() を新しい ServiceBuilder() に追加し、それに応じて出力を更新しました。

役に立ちましたか?

解決

この行を変更します:

Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);

のために:

Token accessToken = service.getAccessToken(requestToken, verifier);


編集

重要な未承認部分全体は、次のコード部分に起因します。

OAuthRequest orequest = new OAuthRequest(Verb.GET, "http://vimeo.com/api/rest/v2");
orequest.addQuerystringParameter("method", "vimeo.test.null");
Response send = orequest.send();
System.out.println(send.getBody());

署名せずに API ルート (これが有効なリソースかどうかはわかりません) に対して GET リクエストを実行しようとしています。もちろん、不正なエラーが発生します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top