我已經嘗試了兩種不同的方法來做到VIMEO先進的API認證。請看以下兩個: -爲什麼使用Perl的Net :: OAuth的失敗我在使用Vimeo的先進的API認證嘗試?
1方法:
#!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_nonce=$oauth_nonce&oauth_signature_method=HMAC-SHA1&oauth_timestamp=$timestamp&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=HMAC-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>
上面使用的消費者密鑰是一個有效的(儘管在上面不共享)。在直接擊中的Mozilla瀏覽器上面的搜索URL拋出這個錯誤:「通過的oauth_signature是無效的。」 請讓我知道確切位置的代碼有錯誤。我已按照所提供的OAuth規範:http://vimeo.com/api/docs/oauth
第二個方法:
#!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 = "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/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->verify;
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;
這種方法也拋出上述錯誤消息:「401未授權」,雖然沒有打在瀏覽器的URL,它拋出的相同'無效的oauth簽名錯誤'。由於這個人在Net :: Oauth的第一步拋出錯誤,我無法繼續前進。任何投入都非常感謝。
在你的第一種方法中,你有'使用URI :: Escape;「http:// vimeo。com/api/rest/v2 /「' –