I am trying to pull data from API, and getting this error. I have searched same file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known but did't understand how to fix
file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known
Here is my code
<?php namespace AdClass;
use stdClass;
class AdInfo{
private $domain;
private $widget_id;
private $api_key;
private $pub_id;
public function __construct($domain, $widget_id, $api_key, $pub_id)
{
$this->domain = $domain;
$this->widget_id = $widget_id;
$this->api_key = $api_key;
$this->pub_id = $pub_id;
}
public function getDomain()
{
return $this->domain;
}
public function getWidgetId()
{
return $this->widget_id;
}
public function getApiKey()
{
return $this->api_key;
}
public function getPubId()
{
return $this->pub_id;
}
public function getAdContent()
{
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://api.revcontent.com/api/v1',
CURLOPT_USERAGENT => 'Codular Sample cURL Request',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'api_key' => $this->api_key,
'pub_id' => $this->pub_id,
'widget_id' => $this->widget_id,
'domain' => $this->domain,
'format' => 'json',
'sponsored_offset' => '0',
'internal_count' => '3',
'internal_offset' => '2'
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
return $resp;
}
}
?>
index.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include(dirname(__FILE__).'/AdClass/AdInfo.php');
$domain = "realtimepolitics.com";
$widget_id = XXXX;
$api_key = "XXXXXX";
$pub_id = XXXX;
$adobj = new AdClass\AdInfo($domain, $widget_id, $api_key, $pub_id);
$response = $adobj->getAdContent();
echo "<pre>";
print_r($response);