singh.ashwini has asked for the wisdom of the Perl Monks concerning the following question:

I have tried two different approach to do vimeo advanced api authentication (which include vimeo search api authentication in this case) and I were not successful using any of them. Please find both the approaches:-

1st Approach:

#!perl + + use strict; use warnings; use Digest::HMAC_SHA1; use Data::Dump qw /dump/; use URI::Escape; use Net::OAuth; use MIME::Base64; use LWP::UserAgent; # Authorize a user + + my $consumer_key = "CONSUMERKEY"; my $secret = "SECRET"; my $method = "vimeo.videos.search" ; my $oauth_nonce = int( rand( 2**32 ) ) ; my $timestamp = time ; my $query = "happy" ; my $url = "http://vimeo.com/api/rest/v2/" ; my $str = "method=$method&oauth_consumer_key=$consumer_key&oauth_non +ce=$oauth_nonce&oauth_signature_method=HMAC-SHA1&oauth_timestamp=$tim +estamp&oauth_version=1.0&query=$query"; $str = uri_escape( $str) ; $url = uri_escape( $url) ; my $secret_key = $secret . '&'; my $base_str = "GET" . "&" . $url . "&" . $str ; my $hmac = Digest::HMAC_SHA1->new( $secret_key ) ; $hmac->add($base_str) ; my $oauth_signature = $hmac->b64digest ; $oauth_signature = encode_base64($oauth_signature ); chomp $oauth_signature; $oauth_signature = uri_escape( $oauth_signature ); my $v_search_url = "http://vimeo.com/api/rest/v2? method=$method&oauth +_consumer_key=$key&oauth_nonce=$oauth_nonce&oauth_signature_method=HM +AC-SHA1&oauth_timestamp=$timestamp&oauth_version=1.0&oauth_signature= +$oauth_signature&query=$query" ; my $browser = LWP::UserAgent->new; my $res = $browser->get( $v_search_url ); print $res->content; The response content throws following error:- <?xml version="1.0" encoding="UTF-8"?> <rsp generated_in="0.0024" stat="fail"> <err code="401" expl="The consumer key passed was not valid." msg= +"Invalid consumer key"/> </rsp>

The consumer key used above is a valid one (Not shared though on top). On hitting the above search url directly on mozilla browser throws this error: "The oauth_signature passed was not valid." Please let me know where exactly the code is having error. I have followed the oauth spec provided at: http://vimeo.com/api/docs/oauth

2nd Approach:

#!perl + + use strict; use warnings; use Digest::HMAC_SHA1; use Data::Dump qw /dump/; use URI::Escape; use Net::OAuth; use Net::OAuth::RequestTokenRequest; use MIME::Base64; use LWP::UserAgent; # Authorize a user + + my $consumer_key = "586a3643bbc31e113205ab62afd86689"; my $secret = "1ff16d3829274918"; my $method = "vimeo.videos.search" ; my $oauth_nonce = int( rand( 2**32 ) ) ; my $timestamp = time ; my $query = "happy" ; my $url = "http://vimeo.com/oauth/request_token"; my $request = Net::OAuth::RequestTokenRequest->new( consumer_key => $consumer_key, consumer_secret => $secret, request_url => $url, request_method => 'GET', signature_method => 'HMAC-SHA1', timestamp => $timestamp, nonce => $oauth_nonce, ); die "COULDN'T GET REQUEST SIGN! Check parameters.\n" unless $request-> +sign; die "COULDN'T VERIFY! Check OAuth parameters.\n" unless $request->veri +fy; my $browser = LWP::UserAgent->new; my $post_body = $request->to_post_body; $post_body = "oauth_callback=oob&" . $post_body; my $post_url = $url . '/?' . $post_body; my $res = $browser->get( $post_url ); die $res->status_line unless ($res->is_success); print $res->content;

This method is also failing by throwing above error stating "The consumer key passed was not valid.".

As using Net::Oauth - its giving error in the first step itself, I cannot proceed further. Any inputs will be sincerely appreciated.

Replies are listed 'Best First'.
Re: Perl + vimeo | Getting error in authenticating advanced API's
by moritz (Cardinal) on May 02, 2012 at 13:30 UTC
    Does $request->to_url produce the same output as what you are doing manually? And do you have some other way of checking if the key is valid?
    $str = uri_escape( $str) ;

    This looks rather dubious to me. You are also URL-escaping the & separators, even though you probably shouldn't do that. Instead URI-escape each parameter individually.

    my $v_search_url = "http://vimeo.com/api/rest/v2? method=$method...";

    Are you sure there needs to be a spasce after the question mark?

      request->to_url is similar to the url string manually created in the first approach.

      As specified on vimeo oauth guide link (http://vimeo.com/api/docs/oauth), The base string should be like below:-

      GET&http%3A%2F%2Fvimeo.com%2Fapi%2Frest%2Fv2%2F&method%3Dvimeo.people.getInfo%26oauth_consumer_key%3Dabcdef0123456%26oauth_nonce%3Dr4nd0m1234%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1336052658%26oauth_version%3D1.0%26user_id%3Dbrad

      There is no space in $v_search_url its a typo. (may occured when I had paste the code).

Re: Perl + vimeo | Getting error in authenticating advanced API's
by Anonymous Monk on May 02, 2012 at 14:24 UTC