From f3a74339185116883f228e81ba360103453c913b Mon Sep 17 00:00:00 2001 From: Relisoft Date: Wed, 17 Jan 2018 22:58:53 +0100 Subject: [PATCH 1/2] more options for data --- src/Kdyby/Facebook/Profile.php | 65 ++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/src/Kdyby/Facebook/Profile.php b/src/Kdyby/Facebook/Profile.php index d1eb2f53..c2ccbdb1 100644 --- a/src/Kdyby/Facebook/Profile.php +++ b/src/Kdyby/Facebook/Profile.php @@ -39,6 +39,37 @@ class Profile extends Nette\Object * @var ArrayHash */ private $details; + private $fields = [ + "address", + "name", + "age_range", + "birthday", + "about", + "gender", + "cover", + "devices", + "education", + "first_name", + "hometown", + "inspirational_people", + "interested_in", + "languages", + "last_name", + "link", + "locale", + "location", + "meeting_for", + "middle_name", + "name", + "name_format", + "profile_pic", + "relationship_status", + "religion", + "short_name", + "sports", + "website", + "work" + ]; @@ -69,26 +100,48 @@ public function getId() /** + * Get all details that you can with /me profile * @param string $key * @return ArrayHash|NULL */ - public function getDetails($key = NULL) + public function getDetails() { if ($this->details === NULL) { try { - $this->details = $this->facebook->api('/' . $this->profileId); + $this->details = $this->facebook->api('/' . $this->profileId,NULL,[ + "fields" => join(",",$this->fields) + ]); } catch (FacebookApiException $e) { $this->details = []; } } - if ($key !== NULL) { - return isset($this->details[$key]) ? $this->details[$key] : NULL; - } - return $this->details; } + /** + * @param string $key + * @return ArrayHash|NULL + */ + public function getDetail($key = NULL) + { + if ($this->details === NULL) { + try { + $this->details = $this->facebook->api('/' . $this->profileId,NULL,[ + "fields" => $key + ]); + + } catch (FacebookApiException $e) { + $this->details = []; + } + } + + if ($key !== NULL) { + return isset($this->details[$key]) ? $this->details[$key] : NULL; + } + + return $this->details; + } From fb6eac6126d7c0827a5eaa3f7ad1701dd1b5f9c1 Mon Sep 17 00:00:00 2001 From: Relisoft Date: Wed, 17 Jan 2018 23:02:19 +0100 Subject: [PATCH 2/2] more options for data --- src/Kdyby/Facebook/Profile.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Kdyby/Facebook/Profile.php b/src/Kdyby/Facebook/Profile.php index c2ccbdb1..904f188f 100644 --- a/src/Kdyby/Facebook/Profile.php +++ b/src/Kdyby/Facebook/Profile.php @@ -119,16 +119,17 @@ public function getDetails() return $this->details; } + /** - * @param string $key + * @param array $keys * @return ArrayHash|NULL */ - public function getDetail($key = NULL) + public function getDetail($keys = ["name"]) { if ($this->details === NULL) { try { $this->details = $this->facebook->api('/' . $this->profileId,NULL,[ - "fields" => $key + "fields" => join(",",$keys) ]); } catch (FacebookApiException $e) {