Skip to content

Instantly share code, notes, and snippets.

@toanalien
Created November 15, 2015 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toanalien/19f16a2711a39c30799b to your computer and use it in GitHub Desktop.
Save toanalien/19f16a2711a39c30799b to your computer and use it in GitHub Desktop.
library\XenForo\Helper\Facebook.php
public static function getAccessToken($url, $code)
{
$options = XenForo_Application::get('options');
if (!$options->facebookAppId)
{
return false;
}
try
{
$client = XenForo_Helper_Http::getClient('https://graph.facebook.com/v2.4/oauth/access_token');
$client->setParameterPost(array(
'client_id' => $options->facebookAppId,
'redirect_uri' => $url,
'client_secret' => $options->facebookAppSecret,
'code' => $code
));
$response = $client->request('POST');
$body = $response->getBody();
if (preg_match('#^[{\[]#', $body))
{
$parts = json_decode($body, true);
}
else
{
$parts = XenForo_Application::parseQueryString($body);
}
return $parts;
}
catch (Zend_Http_Client_Exception $e)
{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment