From a00e9d5652eb2be57e08bf04be17e9e4d5db61bf Mon Sep 17 00:00:00 2001 From: Nodge Date: Sun, 3 Jan 2016 16:14:24 +0500 Subject: [PATCH] Use the latest Graph Api (fix #65) --- CHANGELOG.md | 1 + src/services/FacebookOAuth2Service.php | 12 ++++- .../extended/FacebookOAuth2Service.php | 53 +++++++++++++------ 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b98dd6..4063c4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Yii2 EAuth Change Log ### dev * Fixed error param names for Facebook (#63) +* Use the latest Graph Api v2.5 for Facebook (#65) ### 2.3.0 (17.10.2015) * Added InstagramOAuth2Service (#61) diff --git a/src/services/FacebookOAuth2Service.php b/src/services/FacebookOAuth2Service.php index 602092f..b026355 100644 --- a/src/services/FacebookOAuth2Service.php +++ b/src/services/FacebookOAuth2Service.php @@ -41,11 +41,19 @@ class FacebookOAuth2Service extends Service 'authorize' => 'https://www.facebook.com/dialog/oauth', 'access_token' => 'https://graph.facebook.com/oauth/access_token', ]; - protected $baseApiUrl = 'https://graph.facebook.com/'; + protected $baseApiUrl = 'https://graph.facebook.com/v2.5/'; protected function fetchAttributes() { - $info = $this->makeSignedRequest('me'); + $info = $this->makeSignedRequest('me', [ + 'query' => [ + 'fields' => join(',', [ + 'id', + 'name', + 'link' + ]) + ] + ]); $this->attributes['id'] = $info['id']; $this->attributes['name'] = $info['name']; diff --git a/src/services/extended/FacebookOAuth2Service.php b/src/services/extended/FacebookOAuth2Service.php index 7d7df44..56599e1 100644 --- a/src/services/extended/FacebookOAuth2Service.php +++ b/src/services/extended/FacebookOAuth2Service.php @@ -12,22 +12,41 @@ class FacebookOAuth2Service extends \nodge\eauth\services\FacebookOAuth2Service { - protected $scopes = [ - self::SCOPE_EMAIL, - self::SCOPE_USER_BIRTHDAY, - self::SCOPE_USER_HOMETOWN, - self::SCOPE_USER_LOCATION, - self::SCOPE_USER_PHOTOS, - ]; + protected $scopes = [ + self::SCOPE_EMAIL, + self::SCOPE_USER_BIRTHDAY, + self::SCOPE_USER_HOMETOWN, + self::SCOPE_USER_LOCATION, + self::SCOPE_USER_PHOTOS, + ]; - /** - * http://developers.facebook.com/docs/reference/api/user/ - * - * @see FacebookOAuth2Service::fetchAttributes() - */ - protected function fetchAttributes() - { - $this->attributes = $this->makeSignedRequest('me'); - return true; - } + /** + * http://developers.facebook.com/docs/reference/api/user/ + * + * @see FacebookOAuth2Service::fetchAttributes() + */ + protected function fetchAttributes() + { + $this->attributes = $this->makeSignedRequest('me', [ + 'query' => [ + 'fields' => join(',', [ + 'id', + 'name', + 'link', + 'email', + 'verified', + 'first_name', + 'last_name', + 'gender', + 'birthday', + 'hometown', + 'location', + 'locale', + 'timezone', + 'updated_time', + ]) + ] + ]); + return true; + } }