Changeset 32950
- Timestamp:
- 2019-04-01T16:48:53+13:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/is-sheet-music-encore/trunk/dapiclient2.pl
r32931 r32950 48 48 use OAuth::Lite::AuthMethod; 49 49 50 # read_file() 51 # Derived from: 52 # https://stackoverflow.com/questions/953707/in-perl-how-can-i-read-an-entire-file-into-a-string 53 sub read_file 54 { 55 my ($file) = @_; 56 57 my $text = do { 58 local $/ = undef; 59 open my $fh, "<", $file 60 || die "could not open $file: $!"; 61 <$fh>; 62 }; 63 64 chomp($text); 65 return $text; 66 } 67 68 my $DEBUG=1; 69 my $WEB_DISPLAY=0; 50 70 51 71 my $access_key = 'OAUTH_CONSUMER_KEY'; # replace with your access_key 52 72 my $secret_key = 'OAUTH_CONSUMER_SECRET'; # replace with your secret_key 53 73 my $ip_address = 'MY_IP_ADDRESS'; # replace with the IP address of your workstation or server 74 75 if (-f "my_access_key.txt") { 76 $access_key = read_file("my_access_key.txt"); 77 } 78 79 if (-f "my_secret_key.txt") { 80 $secret_key = read_file("my_secret_key.txt"); 81 } 82 83 if (-f "my_ip_address.txt") { 84 $ip_address = read_file("my_ip_address.txt"); 85 } 54 86 55 my $request_url = 'https://babel.hathitrust.org/cgi/htd/volume/pageimage/mdp.39015000000128/1'; 87 my $base_request_url = "https://babel.hathitrust.org/cgi/htd/volume/pageimage/"; 88 89 #my $request_url = $base_request_url."mdp.39015000000128/1"; 90 my $request_url = $base_request_url."mdp.39015070661841/1"; 91 56 92 57 93 my $consumer = OAuth::Lite::Consumer->new … … 61 97 auth_method => OAuth::Lite::AuthMethod::URL_QUERY, 62 98 ); 99 100 if ($DEBUG) { 101 my $params = $consumer->gen_auth_params('GET', $request_url); 102 print STDERR "(Info) Resolved URL for retrieval:\n"; 103 print STDERR "$request_url?v=2&"; 104 print STDERR "oauth_consumer_key=$params->{'oauth_consumer_key'}&"; 105 print STDERR "oauth_timestamp=$params->{'oauth_timestamp'}&"; 106 print STDERR "oauth_nonce=$params->{'oauth_nonce'}&"; 107 print STDERR "oauth_signature_method=$params->{'oauth_signature_method'}&"; 108 print STDERR "oauth_signature=$params->{'oauth_signature'}&"; 109 print STDERR "oauth_version=$params->{'oauth_version'}\n"; 110 } 63 111 64 112 my $response = $consumer->request … … 80 128 } 81 129 82 print CGI::header( 83 Content_type => $content_type, 84 Status => $response->status_line, 85 ); 130 if ($WEB_DISPLAY) { 131 print CGI::header( 132 Content_type => $content_type, 133 Status => $response->status_line, 134 ); 86 135 87 unless ($success) { 88 print "<p><b>Error: " . $response->content . "</b><br/>"; 136 unless ($success) { 137 print "<p><b>Error: " . $response->content . "</b><br/>"; 138 } 139 else { 140 print $response->content; 141 } 89 142 } 90 143 else { 91 144 print $response->content; 92 145 } 93 94 146 exit $success; 95 147
Note:
See TracChangeset
for help on using the changeset viewer.