/**
 * FACEBOOK: This function pulls in a Facebook page's reviews.
 * @return GraphEdge or GraphNode Object, returns an object with the requested content.
 */
function get_facebook_testimonial($testimonial_url)
{
    global $facebook_page_id;
    if ($testimonial_url !== '') {
        $review_story_id = explode('/', $testimonial_url);
        $review_story_id = $review_story_id[5];
        $config = get_facebook_config();
        $fbApp = new Facebook\FacebookApp($config['app_id'], $config['app_secret']);
        $request = new Facebook\FacebookRequest($fbApp, $config['page_access_token'], 'GET', '/' . $facebook_page_id . '/ratings?fields=open_graph_story{id,start_time},review_text,reviewer');
        try {
            $fbClient = new Facebook\FacebookClient();
            $response = $fbClient->sendRequest($request);
            foreach ($response->getGraphEdge() as $graph_item) {
                if ($graph_item['open_graph_story']['id'] === $review_story_id) {
                    return $graph_item->asArray();
                }
            }
            return 'The function returned an error: We couldn’t find a testimonial that matches that link!';
        } catch (Facebook\Exceptions\FacebookResponseException $e) {
            // When Graph returns an error
            throw new ErrorException('GM_FB_1: ' . $e->getMessage() . ' Try logging in with Facebook to fix this issue. ', '1', 0);
        } catch (Facebook\Exceptions\FacebookSDKException $e) {
            // When validation fails or other local issues
            throw new ErrorException('GM_FB_2: ' . $e->getMessage(), '2', 0);
        }
    }
}
function get_facebook_user($facebook_user_id)
{
    $config = get_facebook_config();
    $fbApp = new Facebook\FacebookApp($config['app_id'], $config['app_secret']);
    $request = new Facebook\FacebookRequest($fbApp, $config['access_token'], 'GET', '/' . $facebook_user_id . '?fields=cover');
    try {
        $fbClient = new Facebook\FacebookClient();
        $response = $fbClient->sendRequest($request);
        return $response->getGraphNode()->asArray();
    } catch (Facebook\Exceptions\FacebookResponseException $e) {
        // When Graph returns an error
        echo 'Graph returned an error: ' . $e->getMessage();
        exit;
    } catch (Facebook\Exceptions\FacebookSDKException $e) {
        // When validation fails or other local issues
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
        exit;
    }
}