本文整理汇总了PHP中Facebook::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Facebook::get方法的具体用法?PHP Facebook::get怎么用?PHP Facebook::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook
的用法示例。
在下文中一共展示了Facebook::get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_fb_permissions
/**
* Retrieves granted permissions.
*
* @param string $access_token The user access token.
* @since 0.5
*/
public function get_fb_permissions($access_token)
{
$permissions = array();
if (isset($this->fb_sdk) && $access_token) {
try {
$permissions_query = $this->fb_sdk->get('/me/permissions', $access_token);
$decoded_permissions = $permissions_query->getDecodedBody();
if (isset($decoded_permissions['data'])) {
foreach ($decoded_permissions['data'] as $permission) {
if ('granted' === $permission['status']) {
$permissions[$permission['permission']] = 'granted';
}
}
}
} catch (Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error.
Logger::getLogger('instantarticles-wp-plugin')->error('Graph returned an error: ' . $e->getMessage(), $e->getTraceAsString());
} catch (Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues.
Logger::getLogger('instantarticles-wp-plugin')->error('Facebook SDK returned an error: ' . $e->getMessage(), $e->getTraceAsString());
}
}
if (isset($permissions)) {
// Logged in.
return $permissions;
}
}
示例2: postLogin
public function postLogin()
{
if (\Input::get('fb_access_token')) {
\Facebook::setDefaultAccessToken(\Input::get('fb_access_token'));
try {
$response = \Facebook::get('/me?fields=id');
$fbUserId = $response->getGraphUser()->getProperty('id');
$fbUser = FbUser::firstOrNew(['fb_user_id' => $fbUserId]);
if ($fbUser->save()) {
\Session::put('fb_user_id', $fbUserId);
return \Response::json(['success' => true]);
}
} catch (\Facebook\Exceptions\FacebookSDKException $e) {
return \Response::json(['success' => false, 'errors' => [$e->getMessage()]]);
}
}
return \Response::json(['success' => false]);
}
示例3: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
// Get the latest 250 facebook posts and record likes/comments
$facebookRequest = sprintf('/%s/feed?limit=250&oauth_token=%s&fields=comments.limit(1).summary(true),likes.limit(1).summary(true)', env('FACEBOOK_PAGE_ID', ''), \Config::get('laravel-facebook-sdk.facebook_config.page_access_token'));
$facebookResponse = \Facebook::get($facebookRequest)->getDecodedBody();
foreach ($facebookResponse['data'] as $facebookPost) {
$facebookPostId = explode('_', $facebookPost['id'])[1];
// get facebook post id
$confession = Confession::where('fb_post_id', '=', $facebookPostId)->first();
// get confession associated with fb post
if ($confession) {
$confession->fb_like_count = $facebookPost['likes']['summary']['total_count'];
$confession->fb_comment_count = $facebookPost['comments']['summary']['total_count'];
$confession->save();
}
}
$this->info('Facebook Information Updated!');
}
示例4: addProfile
/**
* TODO: Refactor to somewehere better; somewhere like a UserRepository.
* @param string $provider provider name
* @param \App\Models\User user model
* @param \Laravel\Socialite\Two\User $oauthUser oAuth user object
*/
protected function addProfile($provider, $user, $oauthUser)
{
$pageToken = $oauthUser->token;
$token = $oauthUser->token;
if ($provider == 'facebook') {
// Extend current token to long-lived access token
$response = \Facebook::get('/oauth/access_token?client_id=' . urlencode(env('FACEBOOK_APP_ID')) . '&client_secret=' . urlencode(env('FACEBOOK_APP_SECRET')) . '&grant_type=fb_exchange_token&fb_exchange_token=' . urlencode($oauthUser->token));
if (!isset($response->getDecodedBody()['access_token'])) {
throw new \Exception('User is not a page admin of Facebook page #' . env('FACEBOOK_PAGE_ID', '') . '.');
}
$token = $response->getDecodedBody()['access_token'];
// Get page token (never expires)
try {
$response = \Facebook::get('/' . env('FACEBOOK_PAGE_ID', '') . '?fields=access_token', $token)->getGraphObject();
} catch (\Facebook\Exceptions\FacebookResponseException $e) {
throw new \Exception('User is not a page admin of Facebook page #' . env('FACEBOOK_PAGE_ID', '') . '.');
}
$pageToken = $response['access_token'];
}
$user->profiles()->save(new UserProfile(['provider_id' => $oauthUser->id, 'provider_name' => $provider, 'provider_token' => $oauthUser->token, 'page_token' => $pageToken, 'data' => json_encode($oauthUser->user)]));
}
示例5: catch
}
if (isset($accessToken)) {
if (isset($_SESSION['facebook_access_token'])) {
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
} else {
$_SESSION['facebook_access_token'] = (string) $accessToken;
// OAuth 2.0 client handler
$oAuth2Client = $fb->getOAuth2Client();
// Exchanges a short-lived access token for a long-lived one
$longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($_SESSION['facebook_access_token']);
$_SESSION['facebook_access_token'] = (string) $longLivedAccessToken;
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
}
// validating the access token
try {
$request = $fb->get('/me');
} catch (Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
if ($e->getCode() == 190) {
unset($_SESSION['facebook_access_token']);
$helper = $fb->getRedirectLoginHelper();
$loginUrl = $helper->getLoginUrl('https://apps.facebook.com/APP_NAMESPACE/', $permissions);
echo "<script>window.top.location.href='" . $loginUrl . "'</script>";
exit;
}
} catch (Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
// getting basic info about user
示例6: __get
/**
* Fetch connected grapobjects and store in the property.
*
* @param string $property
* @return mixed
*/
function __get($property)
{
if (empty($this->id)) {
return parent::__get($property);
}
$connections = $this->getKnownConnections();
if (array_key_exists($property, $connections) === false) {
// not a (known) connection?
if ($this->_state === 'id_only') {
$fields = Facebook::get($this->id, $this->_apiParameters);
$this->__set($fields);
$this->_state = 'ready';
unset($this->_apiParameters);
if (array_key_exists($property, $fields)) {
return $fields[$property];
}
}
if ($this->_state === 'partial') {
$fields = Facebook::get($this->id);
$this->__set($fields);
$this->_state = 'ready';
if (array_key_exists($property, $fields)) {
return $fields[$property];
}
}
$fields = get_public_vars(get_class($this));
if (array_key_exists($property, $fields)) {
// is the field defined in the class?
$permissions = static::getFieldPermissions(array('id' => $this->id));
if (isset($permissions[$property]) && $permissions[$property] !== 'denied' && in_array($permissions[$property], Facebook::getInstance()->getPermissions()) === false) {
notice('Field "' . $property . '" requires the "' . $permissions[$property] . '" permission', 'Current permissions: ' . quoted_human_implode(' and ', Facebook::getInstance()->getPermissions()));
}
return parent::__get($property);
}
}
try {
// Retrieve a connection
if (isset($connections[$property]['class'])) {
$parameters = array('fields' => call_user_func(array($connections[$property]['class'], 'getAllowedFields')));
} else {
$parameters = array();
}
$method = 'get' . ucfirst($property);
$this->__set(array($property => $this->{$method}($parameters)));
return $this->{$property};
} catch (\Exception $e) {
report_exception($e);
return parent::__get($property);
}
}