/** * @param array $params * @return NULL|ArrayHash */ public function getPermissions(array $params = array()) { $params = array_merge($params, array('access_token' => $this->facebook->getAccessToken())); try { $response = $this->facebook->api("/{$this->profileId}/permissions", 'GET', $params); if ($response && !empty($response->data[0])) { return ArrayHash::from($response->data[0]); } } catch (FacebookApiException $e) { return NULL; } }
/** * @param array $params * @return NULL|ArrayHash */ public function getPermissions(array $params = array()) { $params = array_merge($params, array('access_token' => $this->facebook->getAccessToken())); try { $response = $this->facebook->api("/{$this->profileId}/permissions", 'GET', $params); if ($response && !empty($response->data)) { $items = array(); if (isset($response->data[0]['permission'])) { foreach ($response->data as $permissionsItem) { $items[$permissionsItem->permission] = $permissionsItem->status === 'granted'; } } elseif (isset($response->data[0])) { $items = (array) $response->data[0]; } return ArrayHash::from($items); } } catch (FacebookApiException $e) { return NULL; } }
public function facebookRegistrationFormSucceeded($form, $values) { $fbUserId = $values->id; unset($values->id); try { if ($this->facebookUserModel->exists($fbUserId)) { $this->flashMessage("Uživatel s tímto FacebookID již je v systému zaregistrován.", "danger"); $this->redirect("in"); } else { $id = $this->model->insert($values); $this->model->update($id, array("enabled" => 1, "active" => 1)); $this->flashMessage("Uživatel byl úspěšně zaregistrován.", "success"); $this->facebookUserModel->add(array("user_id" => $id, "facebook_id" => $fbUserId, "username" => $values->firstname . " " . $values->lastname, "email" => $values->email)); $this->facebookUserModel->authenticate(array($this->facebook->getUser())); $this->facebookUserModel->updateToken($this->facebook->getUser(), $this->facebook->getAccessToken()); } } catch (Exception $e) { $this->flashMessage("Registrace uživatele se nepodařila.", "danger"); } $this->redirect(":Front:Homepage:default"); }
/** * Make a OAuth Request. * * @param string $url The path (required) * @param array $params The query/post data * * @return string The decoded response object * @throws Facebook\FacebookApiException */ public function oauth($url, array $params) { if (!isset($params['access_token'])) { $params['access_token'] = $this->fb->getAccessToken(); } if ($this->fb->getConfig()->verifyApiCalls && isset($params['access_token']) && !isset($params['appsecret_proof'])) { $params['appsecret_proof'] = $this->fb->config->getAppSecretProof($params['access_token']); } if ($params['appsecret_proof'] === false) { unset($params['appsecret_proof']); } // json_encode all params values that are not strings $params = array_map(function ($value) { if ($value instanceof UrlScript) { return (string) $value; } elseif ($value instanceof \CURLFile) { return $value; } elseif (is_bool($value)) { return $value ? '1' : '0'; } return !is_string($value) ? Json::encode($value) : $value; }, $params); return $this->makeRequest($url, $params); }