Created
November 15, 2015 10:23
-
-
Save toanalien/19f16a2711a39c30799b to your computer and use it in GitHub Desktop.
library\XenForo\Helper\Facebook.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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