当前位置: 首页>>代码示例>>PHP>>正文


PHP Facebook::setDefaultAccessToken方法代码示例

本文整理汇总了PHP中Facebook\Facebook::setDefaultAccessToken方法的典型用法代码示例。如果您正苦于以下问题:PHP Facebook::setDefaultAccessToken方法的具体用法?PHP Facebook::setDefaultAccessToken怎么用?PHP Facebook::setDefaultAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Facebook\Facebook的用法示例。


在下文中一共展示了Facebook::setDefaultAccessToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: checkGrantExtension

 /**
  * @see OAuth2\IOAuth2GrantExtension::checkGrantExtension
  */
 public function checkGrantExtension(IOAuth2Client $client, array $inputData, array $authHeaders)
 {
     if (!isset($inputData['facebook_access_token'])) {
         return false;
     }
     $this->facebookSdk->setDefaultAccessToken($inputData['facebook_access_token']);
     try {
         // Try to get the user with the facebook token from Open Graph
         $fbData = $this->facebookSdk->get('/me?fields=email,id,first_name,last_name,name,name_format');
         if (!$fbData instanceof \Facebook\FacebookResponse) {
             return false;
         }
         // Check if a user match in database with the facebook id
         $user = $this->userManager->findUserBy(['facebookId' => $fbData->getDecodedBody()['id']]);
         // If none found, try to match email
         if (null === $user && isset($fbData->getDecodedBody()['email'])) {
             $user = $this->userManager->findUserBy(['email' => $fbData->getDecodedBody()['email']]);
         }
         // If no user found, register a new user and grant token
         if (null === $user) {
             // TODO: Create new user
             return false;
         } else {
             // Else, return the access_token for the user
             // Associate user with facebookId
             $user->setFacebookId($fbData->getDecodedBody()['id']);
             $this->userManager->updateUser($user);
             return array('data' => $user);
         }
     } catch (\FacebookApiExceptionion $e) {
         return false;
     }
 }
开发者ID:eduardoledo,项目名称:schoolmanager,代码行数:36,代码来源:FacebookGrantExtension.php

示例2: fb

 /**
  * Instantiate and return the Facebook object
  *
  * @return Facebook
  */
 public function fb()
 {
     if ($this->facebookApi === null) {
         $this->facebookApi = new Facebook((array) $this->config->get('fb_config'));
         if (!empty($this->config->get('fb_token')->long)) {
             $this->facebookApi->setDefaultAccessToken($this->config->get('fb_token')->long);
         }
     }
     return $this->facebookApi;
 }
开发者ID:amnuts,项目名称:LikeLight,代码行数:15,代码来源:Controller.php

示例3: publishOnPage

 public function publishOnPage(Post $post, $message = null)
 {
     $response = new FacebookPostAsPageResponse();
     $accessToken = $this->getUserLongAccessToken();
     if (!$post->getPublished()) {
         return $response->setException(new \Exception('flash_batch_facebook_post_not_published'));
     }
     if ($accessToken->tokenIsEmpty()) {
         return $response->setException(new \Exception('flash_batch_facebook_access_token_empty'));
     }
     $this->application->setDefaultAccessToken($accessToken->getAccessToken());
     try {
         $getPageAccessToken = $this->application->sendRequest('GET', '/' . $this->pageId, array('fields' => 'access_token'))->getDecodedBody();
         $params = array('message' => null !== $message ? $message : '', 'name' => $post->getTitle(), 'caption' => $post->getDescription(), 'link' => $this->router->generate('front_article_view', array('slug' => $post->getSlug()), true));
         if (count($post->getImages()) > 0) {
             $hompage = $this->router->generate('homepage', array(), true);
             $imgWebPath = $this->assetsHelper->getUrl($post->getPreviewImage()->getWebPath());
             $params['picture'] = $hompage . $imgWebPath;
         }
         $endPoint = null === $post->getFbId() ? $this->pageId . '/feed' : $post->getFbId();
         $postAsPage = $this->application->post('/' . $endPoint, $params, $getPageAccessToken['access_token'])->getDecodedBody();
         $response->setId(isset($postAsPage['id']) ? $postAsPage['id'] : $post->getFbId());
     } catch (\Exception $e) {
         return $response->setException($e);
     }
     return $response;
 }
开发者ID:nathix86,项目名称:bcp-website,代码行数:27,代码来源:FacebookApplicationManager.php

示例4: cancelEvent

 public function cancelEvent($facebook_event_id)
 {
     $user = $this->container->get('security.token_storage')->getToken()->getUser();
     $user_access_token = $user->getFacebookAccessToken();
     if (!$user_access_token) {
         return json_encode(['message' => 'Not logged in', 'success' => false]);
     }
     $this->fb->setDefaultAccessToken($user_access_token);
     $attendResponse = null;
     try {
         $attendResponse = $this->fb->post($facebook_event_id . '/declined');
     } catch (FacebookResponseException $ex) {
         return false;
         // @TODO: Log stack trace.
     }
     $attendResponse = $attendResponse->getGraphNode()->asArray();
     if ($attendResponse['success'] === true) {
         /**
          * @var FacebookEvent $facebookEvent
          */
         $facebookEvent = $this->container->get('doctrine')->getRepository('NFQKVKScraperBundle:FacebookEvent')->getByFacebookId($facebook_event_id);
         $this->container->get('doctrine')->getRepository('NFQKVKScraperBundle:UserEvent')->deleteAttendedEvent($user->getId(), $facebookEvent->getEvent()->getId());
     }
     return $attendResponse;
 }
开发者ID:nfq-akademija-2015-ruduo,项目名称:Kas_vyksta_Kaune,代码行数:25,代码来源:FacebookEventManager.php

示例5: set_fb_request_session

 /**
  * Create an instance of Facebook session
  */
 private function set_fb_request_session()
 {
     $settings = array('app_id' => self::$appId, 'app_secret' => self::$appSecret, 'default_graph_version' => 'v2.5');
     $fb = new Facebook\Facebook($settings);
     $fb->setDefaultAccessToken(self::$fbToken);
     self::$fbSession = $fb;
 }
开发者ID:vitalsaude,项目名称:api,代码行数:10,代码来源:Processor.php

示例6: fbUserInfoAction

 public function fbUserInfoAction()
 {
     $fb = new Facebook(['app_id' => '1475718472749501', 'app_secret' => 'a67fee083c27186f52030ff3a72f24f9', 'default_graph_version' => 'v2.4']);
     try {
         $helper = $fb->getJavaScriptHelper();
         $accessToken = $helper->getAccessToken();
         $fb->setDefaultAccessToken((string) $accessToken);
         $response = $fb->get('/me?locale=en_US&fields=name,email');
         $userNode = $response->getGraphUser();
         $email = $userNode->getField('email');
         $name = $userNode->getField('name');
         $arr = explode("@", $email);
         $login = $arr[0];
         $arr2 = explode(" ", $name);
         $firstname = $arr2[0];
         $lastname = $arr2[1];
         return new JsonResponse(['firstname' => $firstname, 'lastname' => $lastname, 'login' => $login, 'email' => $email]);
     } 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;
     }
     exit;
 }
开发者ID:Aleksandr-Kachura,项目名称:public_html,代码行数:28,代码来源:LoginController.php

示例7: index

 public function index()
 {
     $fb = new Facebook(['app_id' => '178541382481710', 'app_secret' => '00ad5032a61d3ca526c6693f006db028', 'default_graph_version' => 'v2.4']);
     $fb->setDefaultAccessToken('178541382481710|4K7VTpySNyFIp2gIKlAY3T5pXAc');
     $response = $fb->get('/LesGetsOfficiel/feed?fields=id,message,full_picture,link,type&limit=100');
     $response = $response->getDecodedBody();
     debug($response);
     die;
 }
开发者ID:Aerue,项目名称:avalia,代码行数:9,代码来源:FacebookController.php

示例8: createFacebookLiveVideo

 /**
  * @param LiveBroadcast  $liveBroadcast
  * @param OutputFacebook $outputFacebook
  * @return null|string
  * @throws LiveBroadcastOutputException
  */
 public function createFacebookLiveVideo(LiveBroadcast $liveBroadcast, OutputFacebook $outputFacebook)
 {
     if (!$this->facebookSDK) {
         $this->initFacebook();
     }
     try {
         $params = array('title' => $liveBroadcast->getName(), 'description' => $liveBroadcast->getDescription());
         $this->facebookSDK->setDefaultAccessToken($outputFacebook->getAccessToken());
         $response = $this->facebookSDK->post($outputFacebook->getEntityId() . '/live_videos', $params);
     } catch (FacebookResponseException $ex) {
         throw new LiveBroadcastOutputException('Facebook exception: ' . $ex->getMessage());
     } catch (FacebookSDKException $ex) {
         throw new LiveBroadcastOutputException('Facebook SDK exception: ' . $ex->getMessage());
     }
     $body = $response->getDecodedBody();
     if (array_key_exists('stream_url', $body)) {
         return $body['stream_url'];
     }
     return null;
 }
开发者ID:martin1982,项目名称:live-broadcast-bundle,代码行数:26,代码来源:FacebookApiService.php

示例9: getAuthContainer

 /**
  * @param $userId
  *
  * @return FacebookAdsAuthContainer
  */
 public function getAuthContainer($userId)
 {
     $oauthTokens = $this->MediaPlatformUser->getOauthTokens($userId);
     if (empty($oauthTokens)) {
         throw new NotFoundException('Could not find the oauth tokens for MediaPlatformUser #' . $userId . '.');
     }
     $facebookAuthContainer = new FacebookAdsAuthContainer();
     $this->_facebook->setDefaultAccessToken($oauthTokens['OauthToken']['access_token']);
     $facebookAuthContainer->facebookSdk = $this->_facebook;
     $facebookAuthContainer->facebookAds = Api::init(Configure::read('FacebookAds.app_id'), Configure::read('FacebookAds.app_secret'), $oauthTokens['OauthToken']['access_token']);
     $this->_sendEventIfTokenExpiresInTwoWeeks($userId, $oauthTokens['OauthToken']['token_expires']);
     return $facebookAuthContainer;
 }
开发者ID:ExpandOnline,项目名称:AuthManager,代码行数:18,代码来源:FacebookAdsAuthManager.php

示例10: __invoke

 /**
  * Example middleware invokable class
  *
  * @param  \Psr\Http\Message\ServerRequestInterface $request  PSR7 request
  * @param  \Psr\Http\Message\ResponseInterface      $response PSR7 response
  * @param  callable                                 $next     Next middleware
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function __invoke($request, $response, $next)
 {
     if (isset($_REQUEST['accessToken'])) {
         $accessToken = $_REQUEST['accessToken'];
         $this->fb->setDefaultAccessToken($accessToken);
     } else {
         /* @var $helper FacebookJavaScriptHelper */
         $helper = $this->fb->getJavaScriptHelper();
         $accessToken = $helper->getAccessToken();
     }
     if (!isset($accessToken)) {
         die("Not logged in or request expired");
     }
     try {
         /* @var $fbresponse FacebookResponse */
         $fbresponse = $this->fb->get('/me?fields=id', $accessToken);
         $user = $fbresponse->getGraphUser();
     } catch (Exception $e) {
         die($e->getMessage());
     }
     $next->setArgument('userid', $user->getId());
     $response = $next($request, $response);
     return $response;
 }
开发者ID:vidhu,项目名称:FoodBucketList-API,代码行数:33,代码来源:FBAuthMiddleWare.php

示例11: getFacebookFriends

 private static function getFacebookFriends($user, $token)
 {
     $ids = array();
     $fbConfig['default_access_token'] = $token;
     $fb = new Facebook(Config::get('services.facebook'));
     $fb->setDefaultAccessToken($token);
     $response = $fb->get('/me/friends', $token)->getDecodedBody()['data'];
     $friendsList = $response;
     foreach ($friendsList as $friend) {
         $userAuth = UserAuthToken::where('service', 'facebook')->where('service_id', $friend['id'])->first();
         if ($userAuth) {
             $user_id = $userAuth->user->id;
             $ids[$user_id] = $userAuth->service_id;
         }
     }
     //ids: array(user_id => facebook_id)
     return $ids;
 }
开发者ID:naomilwx,项目名称:sharetaxi,代码行数:18,代码来源:User.php

示例12: 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;
 }
开发者ID:Mziserman,项目名称:4ltrophy,代码行数:23,代码来源:FacebookFeedCatcher.php

示例13: fbcallback

 public function fbcallback()
 {
     //Initialize facebook api
     $fb = new Facebook(['app_id' => self::FB_APP_ID, 'app_secret' => self::FB_APP_SECRET, 'default_graph_version' => self::FB_APP_VERSION]);
     $helper = $fb->getRedirectLoginHelper();
     try {
         $accessToken = $helper->getAccessToken();
     } catch (Exceptions\FacebookResponseException $e) {
         // When Graph returns an error
         echo 'Graph returned an error: ' . $e->getMessage();
         exit;
     } catch (Exceptions\FacebookSDKException $e) {
         // When validation fails or other local issues
         echo 'Facebook SDK returned an error: ' . $e->getMessage();
         exit;
     }
     if (isset($accessToken)) {
         // Logged in!
         $fb->setDefaultAccessToken($accessToken);
         try {
             $response = $fb->get('/me?locale=en_US&fields=name,email,gender,age_range,picture,first_name,last_name,middle_name,birthday,hometown');
             $userNode = $response->getGraphUser();
         } catch (Exceptions\FacebookResponseException $e) {
             // When Graph returns an error
             echo 'Graph returned an error: ' . $e->getMessage();
             exit;
         } catch (Exceptions\FacebookSDKException $e) {
             // When validation fails or other local issues
             echo 'Facebook SDK returned an error: ' . $e->getMessage();
             exit;
         }
         $this->loadComponent('GeoIP');
         $pictureUser = $userNode->getPicture()->asArray();
         $userNode = array('type' => 0, 'status' => 1, 'password' => str_replace(' ', '', strtolower($userNode->getName())), 'email' => $userNode->getEmail(), 'full_name' => $userNode->getName(), 'gender' => $userNode->getGender(), 'image' => $pictureUser['url'], 'birthday' => $userNode->getBirthday(), 'address' => $userNode->getHometown(), 'facebook' => 'https://www.facebook.com/' . $userNode->getId());
         // Now you can redirect to another page and use the
         $this->request->session()->write('fb_user', $userNode);
         $this->redirect('/users/register');
     }
 }
开发者ID:beautifullife,项目名称:FacebookOAuth,代码行数:39,代码来源:FloginController.php

示例14: getTokenFromRedirect

 /**
  * This implementation follow instruction
  *
  * @see https://developers.facebook.com/docs/php/gettingstarted/5.0.0
  *
  * @return AccessToken
  */
 public function getTokenFromRedirect()
 {
     $token = null;
     try {
         $token = $this->getLoginHelper()->getAccessToken($this->getRedirectUrl());
         // exchange a long-live access token
         $oAuth2Client = $this->facebook->getOAuth2Client();
         $token = $oAuth2Client->getLongLivedAccessToken($token);
     } catch (FacebookResponseException $e) {
         throw new \RuntimeException('Graph returned an error: ' . $e->getMessage());
     } catch (FacebookSDKException $e) {
         // When validation fails or other local issues
         throw new \RuntimeException('Facebook SDK returned an error: ' . $e->getMessage());
     }
     if (!$token instanceof AccessToken) {
         throw new \RuntimeException('Could not authorize request on Facebook');
     }
     // store access token
     $_SESSION[self::FACEBOOK_SESSION_KEY] = $token->__toString();
     $this->facebook->setDefaultAccessToken($token);
     return $token;
 }
开发者ID:kendolabdev,项目名称:kendoplatform,代码行数:29,代码来源:FacebookAdapter.php

示例15: loginFacebookUser

 /**
  * This method save or log in a user when is using FacebookAccount
  * @param $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 private function loginFacebookUser($request)
 {
     //load the facebook SDK object
     $fb = new Facebook(['app_id' => env('FB_API_ID'), 'app_secret' => env('FB_API_SECRET'), 'default_graph_version' => 'v2.2']);
     //set the token that whe receive from the request APP
     $fb->setDefaultAccessToken($request->input('token'));
     //Get the graph query
     try {
         $response = $fb->get('/me?fields=id,name,email');
         $fbUser = $response->getGraphUser();
     } catch (FacebookResponseException $e) {
         return response()->json($e->getMessage(), 401);
     } catch (FacebookSDKException $e) {
         return response()->json($e->getMessage(), 400);
     }
     //instantiate the new user
     $user = new User();
     //find by facebook_id and get the mongodb collection for users
     $users = $user->getCollection();
     $result = $users->findOne(['facebook_id' => $fbUser['id']]);
     if ($result) {
         var_dump('log in process by idfb');
         die;
     }
     //find by email
     $result = $users->findOne(['email' => $fbUser['email']]);
     if ($result) {
         var_dump('log in process by email');
         die;
     }
     //if not found then fill data and save account
     $user->fill($request);
     if (!$user->save()) {
         return response()->json('Error, the user was not created', 400);
     }
     return response()->json('success', 200);
 }
开发者ID:jarriaga,项目名称:endaroo,代码行数:42,代码来源:UserController.php


注:本文中的Facebook\Facebook::setDefaultAccessToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。