Reputation: 21
I tried to get access token via Perl as follows.
my $ua = Mojo::UserAgent->new;
my $base64 = encode_base64 "{id}:{secret}";
my $url = "https://api.pinterest.com/v5/oauth/token";
my $tx = $ua->post(
$url => {
'Authorization' => 'Basic ' . $base64,
'Content-Type' => 'application/x-www-form-urlencoded'
} => form => {
'grant_type' => 'authorization_code',
'code' => {code},
'redirect_uri' => {my redirect url}
}
);
Returned following error.
<HTML><HEAD>
<TITLE>Invalid URL</TITLE>
</HEAD><BODY>
<H1>Invalid URL</H1>
The requested URL "http://%5bNo%20Host%5d/v5/oauth/token", is invalid.<p>
Reference #9.5758c317.1698500314.d8e9663
</BODY></HTML>
Anyone know the reason? What is above URL? "http://%5bNo%20Host%5d/v5/oauth/token"
How to fix this? And I want to know what URL is that? Probably that was encoded.
"http://[No Host]/v5/oauth/token"
==================================================
And I tried that few times with same code. I got different messages as follows. It is very weird...
{"code":1,"message":"Missing request body"}
{"code":1,"message":"Invalid parameters."}
Upvotes: 1
Views: 670
Reputation: 21
Self solved.
$base64 had unexpected CRLF. When I added chomp($base64), problem solved. Is the encode_base64 will add CRLF automatically? I'll see original code.
Many thanks!
Upvotes: 1