public function FacebookAlbum::get in Facebook Album 8
Make a request to the specified url and return a converted response
Parameters
string $call_path: An extra path to be appended to the api's base url i.e. (albums/)
array $parameters: Query string parameters to be appended to the api's base url
Return value
mixed A response rendered as an array
Overrides FacebookAlbumInterface::get
File
- src/
FacebookAlbum.php, line 81 - Contains \Drupal\facebook_album\FacebookAlbum.
Class
- FacebookAlbum
- Facebook Album.
Namespace
Drupal\facebook_albumCode
public function get($call_path = '', $parameters = array()) {
$config = $this->configFactory
->get('facebook_album.settings')
->get();
// Add our access token
if (!empty($config['access_token'])) {
$parameters['access_token'] = $config['access_token'];
}
$content_type = [
0 => 'text/json',
];
$query = http_build_query($parameters);
$url = FACEBOOK_ALBUM_API_BASE_URL . $call_path . '?' . $query;
// Attempt to make the request, log and return otherwise
try {
$response = $this->httpClient
->get($url);
$content_type = $response
->getHeader('Content-Type');
$data = $response
->getBody();
} catch (BadResponseException $e) {
$response = $e
->getResponse();
$data = $response
->getBody()
->getContents();
$this->logger
->warning('BadResponseException - Failed to get data "%error".', array(
'%error' => $e
->getMessage(),
));
} catch (RequestException $e) {
$response = $e
->getResponse();
$data = $response
->getBody()
->getContents();
$this->logger
->warning('RequestException - Failed to get data "%error".', array(
'%error' => $e
->getMessage(),
));
} catch (\Exception $e) {
$response = $e
->getResponse();
$data = $response
->getBody()
->getContents();
$this->logger
->warning('Exception - Failed to get data "%error".', array(
'%error' => $e
->getMessage(),
));
}
return $this
->response_to_array($content_type, $data);
}