You are here

function _facebook_album_fetch_api_response in Facebook Album 7.3

Same name and namespace in other branches
  1. 7.2 facebook_album.module \_facebook_album_fetch_api_response()

Make a curl request to the specified url and return a converted response

Parameters

$path: The api path to make a request to

Return value

mixed A response rendered as an array

4 calls to _facebook_album_fetch_api_response()
facebook_album_ajax_get_albums_next in ./facebook_album.module
Fetch the next or previous set of cover photos from the specified page ID.
facebook_album_ajax_get_album_next in ./facebook_album.module
Fetch the next or previous set of photos from the specified album
facebook_album_ajax_get_photo_url in ./facebook_album.module
Fetch an individual photo url from a Facebook album photo
_facebook_album_fetch_application_access_token in ./facebook_album.admin.inc
Build and make the api call for retrieving application access tokens from the facebook api.

File

./facebook_album.module, line 553

Code

function _facebook_album_fetch_api_response($path) {

  // For consistency
  $cid = 'fba:' . str_replace("/", ":", $path);

  // Check cache first before calling API
  if ($cache = cache_get($cid)) {
    $response = $cache->data;
  }
  else {

    // Add api base.
    $url = API_BASE_URL . '/' . $path;

    // Setup cURL call.
    $cURL = curl_init();
    curl_setopt($cURL, CURLOPT_URL, $url);
    curl_setopt($cURL, CURLOPT_HTTPGET, TRUE);
    curl_setopt($cURL, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($cURL, CURLOPT_HTTPHEADER, [
      'Content-Type: application/json',
      'Accept: application/json',
    ]);
    $result = curl_exec($cURL);
    $content_type = curl_getinfo($cURL, CURLINFO_CONTENT_TYPE);
    curl_close($cURL);
    $response = _facebook_album_api_response_to_array($content_type, $result);

    // Cache it if good.
    if (!isset($response['error'])) {
      cache_set($cid, $response, 'cache');
    }
  }
  return $response;
}