<?php

/**
 * @param $fb
 * @param $fbSetup
 * @param $request_string
 * @param $conversionFnName
 * @return mixed
 */
function perform_query($fb, $fbSetup, $request_string, $conversionFnName){
    ////// PERFORM API REQUEST //////
    try {
        // Returns a `Facebook\FacebookResponse` object
        $response = $fb->get(
            $request_string,
            $fbSetup["default_access_token"]
        );
    } catch(Facebook\Exceptions\FacebookResponseException $exception) {
        echo "Graph returned an error: " . $exception->getMessage();
        return [];
    } catch(Facebook\Exceptions\FacebookSDKException $exception) {
        echo "Facebook SDK returned an error: " . $exception->getMessage();
        return [];
    }
    ////// end PERFORM API REQUEST //////
    ////// HANDLE RESULT //////
    $graph_element = $response->$conversionFnName();
    ////// end HANDLE RESULT //////
    return $graph_element;
}
