【问题标题】:getting error 303 invalid signature when using vimeo apis使用 vimeo api 时收到错误 303 无效签名
【发布时间】:2012-02-13 17:49:23
【问题描述】:

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

网址:vimeo.com/api/rest/v2?method=vimeo.oauth.checkAccessToken

基本字符串: GET&http%3A%2F%2Fvimeo.com%2Fapi%2Frest%2Fv2&method%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" 

【问题讨论】:

    标签: java api oauth vimeo


    【解决方案1】:

    不知道您是否仍然遇到此问题,但您可以尝试使用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;
      }
    

    【讨论】:

      【解决方案2】:

      伙计们,我有几乎类似的问题。

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

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

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

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

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

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

      每次都刷新页面以获取正确的网址。 URL 不能多次使用。 Vimeo 将期望每个请求都有新的 url。

      【讨论】:

        猜你喜欢
        • 2016-10-18
        • 2013-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-02
        • 1970-01-01
        • 2023-04-02
        相关资源
        最近更新 更多