1

This is my code to get the oauth tokens and authorize my app for vimeo. This works fine:

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();
        }
    }

However, in performApiCall() I need to do this:

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

                                            );  

How can I get oauth_nonce, oauth_timestamp and oauth_signature?

s.d
  • 4,017
  • 5
  • 35
  • 65
Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193
  • http://stackoverflow.com/questions/7220295/vimeo-advanced-api-how-to-connect-via-oauth does this help you ? or this http://developer.vimeo.com/apis/advanced#oauth – Vrashabh Irde Nov 02 '12 at 06:00
  • no actually i am successful in authenticating with the vimeo... The only problem is how to pass this query because I dont know the values of my oAuth Session – Muhammad Umar Nov 02 '12 at 06:21

2 Answers2

2
  1. Re oauth_timestamp: AFAIK, you set the timestamp yourself to the current timestamp. If you run into problems (vimeo expects the timestamp to not differ more than a few seconds before or after what it thinks is the current timestamp, cf. the vimeo forum thread here), try fiddling with the system time you use (e.g., server time).

  2. Re oauth_nonce: The nonce value is a "random string, uniquely generated by the client to allow the server to verify that a request has never been made before" (The OAuth 1.0 Protocol).

  3. Re oath_signature: The client generates its own signature. From The OAuth 1.0 Protocol:

The client declares which signature method is used via the "oauth_signature_method" parameter. It then generates a signature (or a string of an equivalent value) and includes it in the "oauth_signature" parameter. The server verifies the signature as specified for each method.

In short: you don't "GET" these values from somewhere, you'll have to create them.

I'd really like to refer you to The OAuth 1.0 Protocol once again, it's fairly easy to read and should get you sorted for most of the queries you might have :).

Hope this helps.

Community
  • 1
  • 1
s.d
  • 4,017
  • 5
  • 35
  • 65
0

From http://developer.vimeo.com/apis/advanced

If you’re totally unfamiliar with OAuth, we recommend that you read hueniverse’s OAuth 1.0 Guide before you continue. OAuth is complicated, and he does a great job of explaining the process. Twitter’s guide is also very good.

Also watch the following resources (may help you)

Md Mahbubur Rahman
  • 2,065
  • 1
  • 24
  • 36
  • mate, I have sucessfully authenticated with vimeo using google oauth api. However I can't figure out how to get signature timestamp and nonce. – Muhammad Umar Nov 08 '12 at 10:51
  • @s.d yes i did, inface google api create its own signate to authenticate. Once authenticated i have no idea how to get these values. That;s what my question is :) – Muhammad Umar Nov 09 '12 at 15:44