Skip to content

Instantly share code, notes, and snippets.

@tstachl
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tstachl/9cee3c2416029e6683b4 to your computer and use it in GitHub Desktop.
Save tstachl/9cee3c2416029e6683b4 to your computer and use it in GitHub Desktop.
Calling the Desk.com API in perl using Net::OAuth.
use strict;
use warnings;
use Net::OAuth 0.20;
use Data::Random qw(:all);
$Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A;
use HTTP::Request::Common;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $request = Net::OAuth->request('protected resource')->new(
consumer_key => 'CONSUMER_KEY',
consumer_secret => 'CONSUMER_SECRET',
request_url => 'https://SUBDOMAIN.desk.com/api/v2/users/me',
request_method => 'GET',
signature_method => 'HMAC-SHA1',
timestamp => time,
nonce => join('', rand_chars(size=>16, set=>'alphanumeric')),
version => '1.0',
token => 'TOKEN',
token_secret => 'TOKEN_SECRET'
);
$request->sign;
my $res = $ua->request(GET $request->to_url);
print $res->content;
@shardiwal
Copy link

It doesn't seems to authenticate user. regardless of adding consumer key, secret and token, token_secret.

@tstachl
Copy link
Author

tstachl commented May 18, 2015

@shardiwal did you change the subdomain as well, if your site has a cname + ssl please change the host.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment