Signing URL – Perl

This example illustrates how to sign request URL’s using Perl.

Definition

Name Type Summary
$urlDomain string (required) URL of the service (ex: http://uk.shopping.yahooapis.com)
$urlPath string (required) Path and query for the service (ex: /V2/search?query=ipod)
$partner string (required) Affiliate Id
$key string (required) Affiliate secret key

Please note that your query must be encoded if you use characters with accents.

Sample Class

		sub UrlSigner {

			my ($urlDomain, $urlPath, $partner, $key) = @_;

		    # get the timestamp
		    my $time = time;

		    # replace " " by "+" in url path
		    $urlPath =~ s/\s/+/g;

		    # format URL
		    my $URLtmp = $urlPath . "&aid=" . $partner . "&timestamp=" . $time;

		    my $tokken = md5_base64($URLtmp . $key) . '--';
		    $tokken =~ tr/\+\/=/._-/;

		    return $urlDomain . $URLtmp . "&hash=" . $tokken;
			}

Simply call the function to generate the appropriate URL:

		my $req = UrlSigner("http://uk.shopping.yahooapis.com", "/V2/search?query=sony","96912373", "passwordfor96912373");