PerlMonger79 has asked for the wisdom of the Perl Monks concerning the following question:

Guys,
So I'm trying to find a perl script to request an OAUTH2 Access Token, and I've came across a few which haven't worked out. So I stumbled on this script for the chilkat module but it also doesn't work, but I think it seems promising. The script code and error outputs are below. Can someone please let me know what I'm doing wrong? I downloaded the correct chilkat version for my perl version and did not get any errors when manually installing the module.
#!/usr/bin/perl -w use strict; use warnings; use chilkat(); $rest = chilkat::CkRest->new(); # URL: https://xxx.xx.xx.xx/api/v2/access/token $bTls = 1; $port = 443; $bAutoReconnect = 1; $success = $rest->Connect("xxx.xx.xx.xx",$port,$bTls,$bAutoReconnect); if ($success != 1) { print "ConnectFailReason: " . $rest->get_ConnectFailReason() . "\r +\n"; print $rest->lastErrorText() . "\r\n"; exit; } $rest->SetAuthBasic("username","password"); $json = chilkat::CkJsonObject->new(); $json->UpdateString("grant_type","client_credentials"); $rest->AddHeader("Content-Type","application/json"); $sbRequestBody = chilkat::CkStringBuilder->new(); $json->EmitSb($sbRequestBody); $sbResponseBody = chilkat::CkStringBuilder->new(); $success = $rest->FullRequestSb("POST","/api/v2/access/token",$sbReque +stBody,$sbResponseBody); if ($success != 1) { print $rest->lastErrorText() . "\r\n"; exit; } $respStatusCode = $rest->get_ResponseStatusCode(); if ($respStatusCode >= 400) { print "Response Status Code = " . $respStatusCode . "\r\n"; print "Response Header:" . "\r\n"; print $rest->responseHeader() . "\r\n"; print "Response Body:" . "\r\n"; print $sbResponseBody->getAsString() . "\r\n"; exit; } $jsonResponse = chilkat::CkJsonObject->new(); $jsonResponse->LoadSb($sbResponseBody); $access_token = $jsonResponse->stringOf("access_token"); $created_at = $jsonResponse->stringOf("created_at"); $expires_in = $jsonResponse->IntOf("expires_in"); $refresh_token = $jsonResponse->stringOf("refresh_token"); $token_type = $jsonResponse->stringOf("token_type"); $account_id = $jsonResponse->IntOf("account_id");


Output:

[myname@localhost scripts]$ ./test.pl Can't load '/usr/local/share/perl5/libchilkat.so' for module chilkat: +/usr/local/share/perl5/libchilkat.so: undefined symbol: PL_stack_base + at /usr/lib64/perl5/DynaLoader.pm line 193. at /usr/local/share/perl5/chilkat.pm line 11. Compilation failed in require at ./test.pl line 4. BEGIN failed--compilation aborted at ./test.pl line 4.

Replies are listed 'Best First'.
Re: Issue with Chilkat module
by marto (Cardinal) on Feb 26, 2022 at 08:19 UTC
      I abandoned using this method as i could resolve my issue. I decided to search other methods.