user4271704
user4271704

Reputation: 763

Why Bit.ly v4 API returns INVALID_CONTENT_TYPE_HEADER?

I am getting error. I use this curl:

$url = "https://api-ssl.bitly.com/v4/shorten";
$data = array('long_url' => 'http://www.google.com');

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$header = array('Authorization: Bearer ffaaf96dd9e.........');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$response = curl_exec($ch);
curl_close($ch);
print($response);

and I am getting this response:

HTTP/2 406 
server: nginx
date: Sun, 27 Oct 2019 09:01:26 GMT
content-type: application/json
content-length: 41
strict-transport-security: max-age=31536000; includeSubDomains
x-xss-protection: 1; mode=blockFilter
x-content-type-options: nosniff
x-frame-options: DENY
content-security-policy: default-src 'none
via: 1.1 google
alt-svc: clear

{"message":"INVALID_CONTENT_TYPE_HEADER"}

I googled this error, and no help. Why I am getting this error? Did I do any mistake in coding or should I do something else in my bitly account beside generating token?

EDIT: I googled and found this library in github: https://github.com/phplicengine/bitly I added this to help people comming here by search for the same problem.

Upvotes: 3

Views: 2069

Answers (1)

user4271704
user4271704

Reputation: 763

I discovered the problem was that I have to send parameters in json format to bitly, not array format. I also googled and found this usefull bitly api library in php in github: https://github.com/phplicengine/bitly

Upvotes: 2

Related Questions