使用vimeo apis时收到错误303无效签名

时间:2012-02-13 17:49:24

标签: java api oauth vimeo

..我遇到了无效的签名错误。有人帮我这个吗?我错过了什么吗? Oauth_token是授权后获得的访问令牌

  

URL:vimeo.com/api/rest/v2方法= vimeo.oauth.checkAccessToken

基本字符串: GET&安培; HTTP%3A%2F%2Fvimeo.com%2Fapi%2Frest%2Fv2&安培;方法%3Dvimeo.oauth.checkAccessToken%26oauth_consumer_key%3D763ebd960af20c4844be38d388299f62%26oauth_nonce%3D-5297335925725406200%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1329134906%26oauth_token%3Da61b496a94ebdaa151f1b757bdd54ad7% 26oauth_version%3D1.0

HEADER:OAuth的oauth_consumer_key = “763ebd960af20c4844be38d388299f62”,oauth_nonce = “ - 5297335925725406200”,oauth_signature = “0xBOoOtHG%2BoiAImx3no0bUTTFeU%3D”,oauth_signature_method = “HMAC-SHA1”,oauth_timestamp = “1329134906”,组oauth_token = “a61b496a94ebdaa151f1b757bdd54ad7”,oauth_version = “1.0”

2 个答案:

答案 0 :(得分:0)

不知道您是否仍然遇到此问题,但您可以尝试使用scribe。我一直在开发一个vimeo应用程序,并严重依赖Scribe签名并发送我的请求。以下是身份验证,签名和发送请求的示例:

  private static OAuthService service;
  private static Token accessToken;
  private static String newline = System.getProperty("line.separator");

  public static void main(String[] args) throws Exception {
    // Replace these with your own api key and secret

    String apiKey = "YOUR_API_KEY"; //Give your own API Key
    String apiSecret = "YOUR_API_SECRET"; //Give your own API Secret
    String vimeoAPIURL = "http://vimeo.com/api/rest/v2";
    service = new ServiceBuilder().provider(VimeoApi.class).apiKey(apiKey).apiSecret(apiSecret).build();

    OAuthRequest request;
    Response response;

    accessToken = new Token("AN_INVALID_TOKEN_WILL", "REQUIRE_GETTING_A_NEW_ONE"); //Copy the new token you get here

    accessToken = checkToken(vimeoAPIURL, accessToken, service);
    if (accessToken == null) {
      return;
    }
 }

  /**
  * Checks the token to make sure it's still valid. If not, it pops up a dialog asking the user to
  * authenticate.
  */
  private static Token checkToken(String vimeoAPIURL, Token vimeoToken, OAuthService vimeoService) {
    if (vimeoToken == null) {
      vimeoToken = getNewToken(vimeoService);
    } else {
      OAuthRequest request = new OAuthRequest(Verb.GET, vimeoAPIURL);
      request.addQuerystringParameter("method", "vimeo.oauth.checkAccessToken");
      Response response = signAndSendToVimeo(request, "checkAccessToken", true);
      if (response.isSuccessful()
              && (response.getCode() != 200 || response.getBody().contains("<err code=\"302\"")
              || response.getBody().contains("<err code=\"401\""))) {
        vimeoToken = getNewToken(vimeoService);
      }
    }
    return vimeoToken;
  }

  /**
  * Gets authorization URL, pops up a dialog asking the user to authenticate with the url and the user
  * returns the authorization code
  *
  * @param service
  * @return
  */
  private static Token getNewToken(OAuthService service) {
    // Obtain the Authorization URL
    Token requestToken = service.getRequestToken();
    String authorizationUrl = service.getAuthorizationUrl(requestToken);
    do {
      String code = JOptionPane.showInputDialog("The token for the account (whatever)" + newline
              + "is either not set or is no longer valid." + newline
              + "Please go to the URL below and authorize this application." + newline
              + "Paste the code you're given on top of the URL here and click \'OK\'" + newline
              + "(click the 'x' or input the letter 'q' to cancel." + newline
              + "If you input an invalid code, I'll keep popping up).", authorizationUrl + "&permission=delete");
      if (code == null) {
        return null;
      }
      Verifier verifier = new Verifier(code);
      // Trade the Request Token and Verfier for the Access Token
      System.out.println("Trading the Request Token for an Access Token...");
      try {
        Token token = service.getAccessToken(requestToken, verifier);
        System.out.println(token); //Use this output to copy the token into your code so you don't have to do this over and over.
        return token;
      } catch (OAuthException ex) {
        int choice = JOptionPane.showConfirmDialog(null, "There was an OAuthException" + newline
                + ex + newline
                + "Would you like to try again?", "OAuthException", JOptionPane.YES_NO_OPTION);
        if (choice == JOptionPane.NO_OPTION) {
          break;
        }
      }
    } while (true);
    return null;
  }

  /**
  * Signs the request and sends it. Returns the response.
  *
  * @param request
  * @return response
  */
  public static Response signAndSendToVimeo(OAuthRequest request) throws org.scribe.exceptions.OAuthException {
    service.signRequest(accessToken, request);
    Response response = request.send();
    return response;
  }

答案 1 :(得分:0)

伙计我的问题几乎相似。

我正在使用基本通话,一切正常。但我意识到基本只允许你查询60个视频。每页20个视频。下面是我尝试使用basic实现分页的链接,但代码仅适用于三个页面,即30个视频。

http://projects.tk-fn.com/controls/Vimeo/BKBVideoPage-Backup.html

然后我尝试了高级api,允许每页50页和无限制的视频。 我能够完成所有OAuth实现,但现在的问题是,当我将它放在浏览器中时,url工作正常但在我尝试进行JSONP ajax调用时不起作用。 :(

http://projects.tk-fn.com/controls/Vimeo/OAuthSimple.html

对于那些知道的人。 OAuth接受所有必需的参数,如 Consumer_Key,Secret,NONE(随机字符串),timestamp,oauth_signature(使用整个url创建)。

我找到了一个名为Simple OAuth的类并使用它。

REFRESH页面每次都能获得正确的URL。网址不能多次使用。 Vimeo会在每次请求时都期待新网址。