MKBH_FACEBOOK_APP_ID, 'app_secret' => MKBH_FACEBOOK_APP_SECRET, 'default_graph_version' => 'v3.0', 'default_access_token' => MKBH_FACEBOOK_APP_STATIC_ACCESS_TOKEN ]); } /** * Instantiate, run API request and return decoded body. * * @param $method * @param $endpoint * @param array $params * @param null $accessToken * @param null $eTag * @param null $graphVersion * @return array|null */ function facebookRequestSend($method, $endpoint, array $params = [], $accessToken = null, $eTag = null, $graphVersion = null) { try { $response = facebook()->sendRequest($method, $endpoint, $params, $accessToken, $eTag, $graphVersion); if ($response instanceof \Facebook\FacebookResponse && !$response->isError()) { $appUsage = json_decode( $response->getHeaders()['x-app-usage'] ); $maxMetric = max( $appUsage->call_count, $appUsage->total_cputime, $appUsage->total_time ); if ($maxMetric >= 75) { throw new FacebookThrottleException; } return $response->getDecodedBody(); } else { throw $response->getThrownException(); } } catch (FacebookThrottleException $e) { watchdog('facebookSDK', "Facebook API request [{$method} {$endpoint}] has been throttled!", [], WATCHDOG_ERROR); return NULL; } catch (\Exception $e) { watchdog('facebookSDK', $e->getMessage() . ' in ' . $e->getFile() . ' at ' . $e->getLine() . 'line', [], WATCHDOG_ERROR); return NULL; } }