/** * Load the subscriptions for this Application from Facebook Graph * * @returns void * @throws \Graph\Exception\InvalidArgumentException */ public function fetchSubscriptions() { if ($this->getFieldValue('id') === null) { throw new InvalidArgumentException('Application ID not set'); } $request = new GraphRequest(); $request->setAccessToken($this->getAccessToken()); $request->setNode($this->getFieldValue('id')); $request->setPath('subscriptions'); $response = $request->send(); $json = $response->getBody(true); if ($arr = json_decode($json, true)) { if (isset($arr['data']) && !empty($arr['data'])) { $this->setSubscriptions($response->getBody(true)); } } }
/** * Load the node and return a populated object * * @param string $id unique node id * @param array $fields (optional) array of field names to fetch * * @return $this * @throws FacebookInvalidNodeException */ public function load($id, $fields = array()) { $request = new GraphRequest(); $request->setNode($id); if (count($fields) > 0) { $request->setFields($fields); } $response = $request->send(); $arr = json_decode($response->getBody(true), true); if (is_array($arr)) { foreach ($arr as $key => $val) { $this->setFieldValue($key, $val); } $this->is_new = false; $this->is_modified = false; return $this; } throw new FacebookInvalidNodeException(sprintf('Id %s not valid', $id)); }
/** * Send a notification to a Player using their Facebook userId * * @return boolean true if the message was successfully sent * @throws FacebookInsufficientPermissions * thrown if the facebook user has not given permission (or has revoked permission) to our app * @throws FacebookAuthException * @throws FacebookApiException * @throws FacebookConnectionException * thrown if we are unable to connect to the Facebook HTTP Api */ public function send() { $this->isValid(); $href = $this->buildHrefString(); $request = new GraphRequest(); $request->setNode($this->facebook_user_id)->setHttpMethod('POST')->setPath('notifications')->setAccessToken($this->access_token)->setQueryParameters(array('template' => $this->message, 'href' => $href)); $response = $request->send(); return $response->getBody(); }