本文整理汇总了PHP中Facebook\Facebook::getClient方法的典型用法代码示例。如果您正苦于以下问题:PHP Facebook::getClient方法的具体用法?PHP Facebook::getClient怎么用?PHP Facebook::getClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook\Facebook
的用法示例。
在下文中一共展示了Facebook::getClient方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: facebook
public function facebook()
{
$this->load->library('session');
$fb = new Facebook(['app_id' => '1068933233152181', 'app_secret' => 'cb86048c2ca95c034a26fe239e48a8eb']);
/*
*
*@Trying to get and set the fucking token
*
*/
if (null !== $this->session->userdata('fb_token') && !empty($this->session->userdata('fb_token'))) {
$accessToken = $this->session->userdata('fb_token');
} else {
$jsHelper = $fb->getJavaScriptHelper();
// @TODO This is going away soon
$facebookClient = $fb->getClient();
try {
$accessToken = $jsHelper->getAccessToken($facebookClient);
$this->session->set_userdata('fb_token', $accessToken);
} catch (Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
} catch (Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
}
}
//@TODO exchange echo for error
/*
*
*@After we get the token, get user name & email with it,
* assign it a pin code, register him in the db + token + time of creation
* redirect him to upload controller
*/
if (isset($accessToken)) {
// Logged in.
//@TODO set a time=10min session if !sess[time]
//@TODO check for Message: Error validating access token: Session has expired on Sunday, 20-Dec-15 13:00:00 PST. The current time is Sunday, 20-Dec-15 13:03:57 PST.
$response = $fb->get('/me?locale=en_US&fields=name,email', $accessToken);
$userNode = $response->getGraphUser();
$this->session->set_userdata('name', $userNode['name']);
//@TODO figure out a way to use pin once, maybe through session.
$data['access_token'] = $accessToken;
$this->load->model('register_model');
//Create & check if pin is in use
do {
$pin = $this->generate_pin();
} while ($this->register_model->check_pin($pin) === FALSE);
if ($this->register_model->add($userNode['name'], $userNode['email'], $pin)) {
$this->session->set_userdata('pin', $pin);
$this->session->redirect(site_url('/upload'));
}
} else {
//@TODO CREATE AN ERROR PAGE
echo "Unable to read JavaScript SDK cookie";
}
}
示例2: getPageDataFromFacebook
/**
* Call Facebook API and fetch page data
*
* @param Facebook ID of the page $page_id
* @param Database Access token $access_token
*
* @return GraphPage
*/
public function getPageDataFromFacebook($page_id, $access_token)
{
$params = array('fields' => 'access_token, picture.width(140).height(140){url}, hometown, about, bio, band_members, artists_we_like, booking_agent, website');
$request = $this->facebook->request('GET', '/' . $page_id, $params, $access_token);
try {
$response = $this->facebook->getClient()->sendRequest($request);
} catch (Exception $e) {
dd($e);
}
return $response->getGraphPage();
}
示例3: fbcallback
public function fbcallback()
{
$fb = new Facebook\Facebook(['app_id' => Config::get("facebook.appId"), 'app_secret' => Config::get("facebook.secret")]);
$jsHelper = $fb->getJavaScriptHelper();
// @TODO This is going away soon
$facebookClient = $fb->getClient();
try {
$accessToken = $jsHelper->getAccessToken($facebookClient);
} catch (Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
return Redirect::to('/')->with('message', 'Graph returned an error: ' . $e->getMessage());
} catch (Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
return Redirect::to('/')->with('message', 'Facebook SDK returned an error: ' . $e->getMessage());
} catch (Exception $e) {
// generic exception
return Redirect::to('/')->with('message', 'There was an error');
}
if (!isset($accessToken)) {
return Redirect::to('/')->with('message', 'There was an error');
}
$response = $fb->get('/me?fields=id,name,email', $accessToken);
$me = $response->getGraphObject();
$gotoProfileCompletePage = false;
$profile = Profile::whereUid($me['id'])->first();
if (empty($profile)) {
$user = new User();
$user->name = $me['name'];
$user->email = $me['email'];
//$user->photo_large = 'https://graph.facebook.com/'.$me['username'].'/picture?type=large';
$user->save();
$profile = new Profile();
$profile->uid = $me['id'];
$profile->username = $me['email'];
$profile->origin = 'fb';
$profile->access_token = $accessToken;
$profile->access_token_secret = $accessToken;
$profile = $user->profiles()->save($profile);
// first time, need to complete profile
$gotoProfileCompletePage = true;
}
$profile->access_token = $accessToken;
$profile->save();
$user = $profile->user;
Auth::login($user);
if ($gotoProfileCompletePage) {
return redirect('/login/complete');
} else {
return redirect('/');
}
}
示例4: indexAction
public function indexAction()
{
// Initialisation de Facebook
$fb = new Facebook(['app_id' => $this->getParameter('facebook.app_id'), 'app_secret' => $this->getParameter('facebook.app_secret'), 'default_graph_version' => $this->getParameter('facebook.default_graph_version'), 'default_access_token' => $this->getParameter('facebook.default_access_token')]);
// Requête sur le nombre de likes
$request = new FacebookRequest($fb->getApp(), $fb->getDefaultAccessToken(), 'GET', '/RadioGatsun', array('fields' => 'likes'));
// Extraction
$likes = $fb->getClient()->sendRequest($request)->getGraphNode()->getField('likes');
$repository = $this->getDoctrine()->getManager()->getRepository('GatsunWebsiteBundle:Publication');
$listePublications = $repository->findBy(array(), array('date' => 'desc'), 5, 0);
$listeVignettes = $this->getDoctrine()->getManager()->getRepository('GatsunWebsiteBundle:Vignette')->findAll();
$listeEmissions = $this->getDoctrine()->getManager()->getRepository('GatsunWebsiteBundle:Emission')->getNextEmissions(2);
return $this->render('GatsunWebsiteBundle:General:accueil.html.twig', array('publications' => $listePublications, 'listeVignettes' => $listeVignettes, 'listeEmissions' => $listeEmissions, 'facebookLikes' => $likes));
}
示例5: getFeed
/**
* @return GraphEdge
*/
public function getFeed()
{
$sinceDate = new \DateTime($this->startingDate);
$request = new FacebookRequest($this->facebookApp, $this->facebookAccessToken, 'GET', sprintf('/%d/posts', $this->facebookPageId), ['fields' => 'message, created_time, status_type, attachments, place', 'since' => $sinceDate->getTimestamp()]);
$fb = new Facebook(["app_id" => $this->facebookApp->getId(), "app_secret" => $this->facebookApp->getSecret(), "default_graph_version" => 'v2.5']);
$fb->setDefaultAccessToken($this->facebookAccessToken);
try {
$response = $fb->getClient()->sendRequest($request);
} catch (FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch (FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$timelineObject = $this->timelineObjectFiller($response->getGraphEdge());
return $timelineObject;
}
示例6: testCanInjectCustomHandlers
public function testCanInjectCustomHandlers()
{
$config = array_merge($this->config, ['http_client_handler' => new FooClientInterface(), 'persistent_data_handler' => new FooPersistentDataInterface(), 'url_detection_handler' => new FooUrlDetectionInterface(), 'pseudo_random_string_generator' => new FooBarPseudoRandomStringGenerator()]);
$fb = new Facebook($config);
$this->assertInstanceOf('Facebook\\Tests\\FooClientInterface', $fb->getClient()->getHttpClientHandler());
$this->assertInstanceOf('Facebook\\Tests\\FooPersistentDataInterface', $fb->getRedirectLoginHelper()->getPersistentDataHandler());
$this->assertInstanceOf('Facebook\\Tests\\FooUrlDetectionInterface', $fb->getRedirectLoginHelper()->getUrlDetectionHandler());
$this->assertInstanceOf('Facebook\\Tests\\FooBarPseudoRandomStringGenerator', $fb->getRedirectLoginHelper()->getPseudoRandomStringGenerator());
}
示例7: testCreatingANewRequestWillDefaultToTheProperConfig
public function testCreatingANewRequestWillDefaultToTheProperConfig()
{
$config = array_merge($this->config, ['default_access_token' => 'foo_token', 'http_client_handler' => new FooClientInterface(), 'persistent_data_handler' => new FooPersistentDataInterface(), 'enable_beta_mode' => true, 'default_graph_version' => 'v1337']);
$fb = new Facebook($config);
$request = $fb->request('FOO_VERB', '/foo');
$this->assertInstanceOf('Facebook\\Tests\\FooClientInterface', $fb->getClient()->getHttpClientHandler());
$this->assertInstanceOf('Facebook\\Tests\\FooPersistentDataInterface', $fb->getRedirectLoginHelper()->getPersistentDataHandler());
$this->assertEquals(FacebookClient::BASE_GRAPH_URL_BETA, $fb->getClient()->getBaseGraphUrl());
$this->assertEquals('1337', $request->getApp()->getId());
$this->assertEquals('foo_secret', $request->getApp()->getSecret());
$this->assertEquals('foo_token', (string) $request->getAccessToken());
$this->assertEquals('v1337', $request->getGraphVersion());
}