I am trying to connect to Moz API V2, using HTTP Request by file get contents function but I am new using this... could you guys help me?
Example HTPP Request in their doc:
POST /v2/url_metrics
Host: lsapi.seomoz.com
Content-Length: [length of request payload in bytes]
User-Agent: [user agent string]
Authorization: Basic [credentials]
{
"targets": ["facebook.com"]
}
Here's the code I am trying:
$url = 'https://lsapi.seomoz.com/v2/url_metrics';
$domains = json_encode(['targets' => 'moz.com']);
$opts = ['http' =>
[
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded\r\n'.
("Authorization: Basic " . base64_encode("mozscape-XXXXX:XXXXX")),
'content-length' => strlen($domains),
'user-agent' => $_SERVER['HTTP_USER_AGENT'],
'content' => $domains,
]
];
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
print_r($result);
Here is the link of documentation : https://moz.com/help/links-api/making-calls/url-metrics
I got nothing when I print result, Probably I am missing some parameter... :(
Thank you for your time :)