这是我的代码,用于获取oauth令牌并授权我的应用使用vimeo。这工作正常:

WebView webview = new WebView(this);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.setVisibility(View.VISIBLE);
        setContentView(webview);

        Log.i(TAG, "Retrieving request token from Vimeo servers");

        try {

            final OAuthHmacSigner signer = new OAuthHmacSigner();
            signer.clientSharedSecret = Constants.CONSUMER_SECRET_VIMEO;

            OAuthGetTemporaryToken temporaryToken = new OAuthGetTemporaryToken(Constants.REQUEST_URL_VIMEO);
            temporaryToken.transport = new ApacheHttpTransport();
            temporaryToken.signer = signer;
            temporaryToken.consumerKey = Constants.CONSUMER_KEY_VIMEO;
            temporaryToken.callback = Constants.OAUTH_CALLBACK_URL;
            OAuthCredentialsResponse tempCredentials = temporaryToken.execute();
            signer.tokenSharedSecret = tempCredentials.tokenSecret;

            OAuthAuthorizeTemporaryTokenUrl authorizeUrl = new OAuthAuthorizeTemporaryTokenUrl(Constants.AUTHORIZE_URL_VIMEO);
            authorizeUrl.temporaryToken = tempCredentials.token;
            String authorizationUrl = authorizeUrl.build();
            Log.d("urlop", authorizationUrl);

            /* WebViewClient must be set BEFORE calling loadUrl! */
            webview.setWebViewClient(new WebViewClient() {

                @Override
                public void onPageStarted(WebView view, String url,Bitmap bitmap)  {
                    System.out.println("onPageStarted : " + url);
                }
                @Override
                public void onPageFinished(WebView view, String url)
                {
                    Log.d("url", url);
                    if (url.startsWith(Constants.OAUTH_CALLBACK_URL)) {
                        try {

                            if (url.indexOf("oauth_token=")!=-1) {

                                String requestToken  = extractParamFromUrl(url,"oauth_token");
                                String verifier= extractParamFromUrl(url,"oauth_verifier");

                                signer.clientSharedSecret = Constants.CONSUMER_SECRET;

                                OAuthGetAccessToken accessToken = new OAuthGetAccessToken(Constants.ACCESS_URL);
                                accessToken.transport = new ApacheHttpTransport();
                                Log.d("abc", "");
                                accessToken.temporaryToken = requestToken;
                                Log.d("abc", accessToken.temporaryToken);
                                accessToken.signer = signer;

                                accessToken.consumerKey = Constants.CONSUMER_KEY;
                                accessToken.verifier = verifier;
                                Log.d("abc", accessToken.verifier);

                                OAuthCredentialsResponse credentials = accessToken.execute();

                                signer.tokenSharedSecret = credentials.tokenSecret;
                                Log.d("abc", signer.tokenSharedSecret);
                                CredentialStore credentialStore = new SharedPreferencesCredentialStore(prefs);
                                credentialStore.write(new String[] {credentials.token,credentials.tokenSecret});
                                view.setVisibility(View.INVISIBLE);
                                performApiCall();
                               // startActivity(new Intent(OAuthAccessTokenActivityVimeo.this,Vimeo.class));
                            }
                            else if (url.indexOf("error=")!=-1)
                            {
                                view.setVisibility(View.INVISIBLE);
                                new SharedPreferencesCredentialStore(prefs).clearCredentials();
                                startActivity(new Intent(OAuthAccessTokenActivityVimeo.this,MainMenu.class));
                            }

                        } catch (IOException e) {
                            e.printStackTrace();
                        }

                    }
                    System.out.println("onPageFinished : " + url);

                }
                private String extractParamFromUrl(String url,String paramName)
                {
                    String queryString = url.substring(url.indexOf("?", 0)+1,url.length());
                    QueryStringParser queryStringParser = new QueryStringParser(queryString);
                    return queryStringParser.getQueryParamValue(paramName);
                }

            });

            webview.loadUrl(authorizationUrl);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }


但是,在performApiCall()中,我需要这样做:

String url = String.format("http://vimeo.com/api/rest/v2&format=json&full_response=1&method=vimeo.videos.search&oauth_consumer_key=%s&oauth_nonce=fb86e833df995307290763917343ae19&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1350908218&oauth_version=1.0&per_page=20&query=umar&sort=newest&summary_response=1",
                                            Constants.CONSUMER_KEY

                                            );


如何获得oauth_nonceoauth_timestampoauth_signature

最佳答案

来自http://developer.vimeo.com/apis/advanced


  如果您完全不熟悉OAuth,建议您阅读
  hueniverse’s OAuth 1.0 Guide,然后再继续。 OAuth是
  复杂,他在解释该过程方面做得很出色。
  Twitter’s guide也很好。


另请注意以下资源(可能会对您有所帮助)


http://developer.vimeo.com/apis/advanced#official-libraries
http://developer.vimeo.com/apis/advanced
http://vimeoapi.tumblr.com/
http://speckyboy.com/2012/10/31/coding-a-vimeo-api-instant-search-app-with-jquery/

10-06 13:58
查看更多