本文整理汇总了PHP中Facebook\Facebook::getAccessToken方法的典型用法代码示例。如果您正苦于以下问题:PHP Facebook::getAccessToken方法的具体用法?PHP Facebook::getAccessToken怎么用?PHP Facebook::getAccessToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook\Facebook
的用法示例。
在下文中一共展示了Facebook::getAccessToken方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: syncUser
/**
* Sync the user back to the linked Facebook account.
*
* <h3>Usage:</h3>
* <pre class="code">
* $auth->syncUser($_POST['access-token']);
* </pre>
*
* @param string $access_token A valid access token for the user to sync up.
*
* @return bool True or false on success.
*/
public function syncUser($access_token)
{
try {
$facebook = new \Facebook(['appId' => FACEBOOK_APP_ID, 'secret' => FACEBOOK_APP_SECRET]);
$facebook->setAccessToken($access_token);
/** @var array $user_profile The array of user data from Facebook */
$user_profile = $facebook->api('/me');
} catch (\Exception $e) {
return false;
}
$user = $this->_usermodel;
if (!$user->exists()) {
// Some config options for new accounts only.
$profiles = $user->get('external_profiles');
if (!is_array($profiles)) {
$profiles = [];
}
$profiles[] = [['type' => 'facebook', 'url' => $user_profile['link'], 'title' => 'Facebook Profile']];
$user->set('external_profiles', $profiles);
// Another component from the user-social component.
// This needs to be unique, so do a little fudging if necessary.
try {
$user->set('username', $user_profile['username']);
} catch (\ModelValidationException $e) {
$user->set('username', $user_profile['username'] . '-' . \Core\random_hex(3));
}
// Sync the user avatar.
$f = new \Core\Filestore\Backends\FileRemote('http://graph.facebook.com/' . $user_profile['id'] . '/picture?type=large');
$dest = \Core\Filestore\Factory::File('public/user/avatar/' . $f->getBaseFilename());
$f->copyTo($dest);
$user->set('avatar', 'public/user/avatar/' . $dest->getBaseFilename());
}
// Get all user configs and load in anything possible.
$user->set('first_name', $user_profile['first_name']);
$user->set('last_name', $user_profile['last_name']);
$user->set('gender', ucwords($user_profile['gender']));
$user->set('facebook_id', $user_profile['id']);
$user->set('facebook_link', $user_profile['link']);
$user->set('facebook_access_token', $facebook->getAccessToken());
}