/** * Auto post to facebook from wordpress/website * Author -> Nasir Uddin Nobin */ function fb_update($ID, $post) { /** * download facebook php sdk https://github.com/facebookarchive/facebook-php-sdk * upload it to your directory and include it * if you paste this code to plugin file use (plugin_dir_path(__FILE__) */ require_once get_template_directory_uri() . '/facebook-php-sdk/autoload.php'; // cleaning html tags and bbcodes $content = strip_tags($post->post_content); $content = preg_replace("/\\[.+\\](.+)|\\s\\s+\\[\\/.+\\]/i", "\$1", $content); // getting $permalink from id $permalink = get_permalink($ID); $fb = new Facebook\Facebook(['app_id' => '{your-ap-id}', 'app_secret' => '{app-secret}', 'default_graph_version' => 'v2.2']); /** * generate your page long live access token * you may use https://developers.facebook.com/tools/explorer * Permissions: manage_pages, publish_pages */ $accessToken = '{give-your-long-live-page-access-token}'; $linkData = ['link' => $permalink, 'message' => short_content($content, $num = 35) . "\n \t\n \tRead more: {$permalink}\n \t\n \t"]; try { $response = $fb->post('/me/feed', $linkData, $accessToken); } catch (Facebook\Exceptions\FacebookResponseException $e) { } catch (Facebook\Exceptions\FacebookSDKException $e) { } }
public function fbLogin() { $fb = new Facebook\Facebook(['app_id' => '893742270708797', 'app_secret' => 'ade43eebafeb020f4c83c324724d72f3', 'default_graph_version' => 'v2.3']); $helper = $fb->getRedirectLoginHelper(); echo $_SERVER['REQUEST_URI']; exit; try { $accessToken = $helper->getAccessToken(); } catch (Facebook\Exceptions\FacebookResponseException $e) { // When Graph returns an error echo 'Graph returned an error: ' . $e->getMessage(); exit; } catch (Facebook\Exceptions\FacebookSDKException $e) { // When validation fails or other local issues echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit; } if (isset($accessToken)) { // Logged in! $_SESSION['facebook_access_token'] = (string) $accessToken; // Now you can redirect to another page and use the // access tokoen from $_SESSION['facebook_access_token'] } var_dump($helper); }
public function getFacebookUserObject() { require_once APPPATH . "../assets/front/social/facebook/autoload.php"; $output_status = 'success'; $access_token_value = NULL; // Create our Application instance (replace this with your appId and secret). $fb = new Facebook\Facebook(['app_id' => FACEBOOK_APP_ID, 'app_secret' => FACEBOOK_SECRET_ID, 'default_graph_version' => 'v2.5']); $helper = $fb->getRedirectLoginHelper(); try { $accessToken = $helper->getAccessToken(); // Returns a `Facebook\FacebookResponse` object $response = $fb->get('/me?fields=id,name,email', $accessToken); $output_message = $user = $response->getGraphUser(); // The OAuth 2.0 client handler helps us manage access tokens $oAuth2Client = $fb->getOAuth2Client(); $access_token_value = (string) $oAuth2Client->getLongLivedAccessToken($accessToken)->getValue(); } catch (Facebook\Exceptions\FacebookResponseException $e) { // echo 'Graph returned an error: ' . $e->getMessage(); $output_message = $e->getMessage(); $output_status = 'error'; } catch (Facebook\Exceptions\FacebookSDKException $e) { // echo 'Facebook SDK returned an error: ' . $e->getMessage(); $output_message = $e->getMessage(); $output_status = 'error'; } return array('status' => $output_status, 'data' => $output_message, 'accessToken' => $access_token_value); }
function GetUserInfo() { $fields = ""; $o = null; $n = null; if (isset($_GET['fields'])) { $o = $_GET['fields'] . ",id"; $n = explode(',', $o); foreach ($n as $field) { $fields .= $field . ","; } //remove last comma $fields = rtrim($fields, ","); } else { return "Missing required param"; exit; } $config = (include "/config.php"); $fb = new Facebook\Facebook(['app_id' => $config['app_id'], 'app_secret' => $config['app_secret'], 'default_graph_version' => 'v2.4']); try { $response = $fb->get('/me?fields=' . $fields, $_SESSION['facebook_access_token']); } catch (Facebook\Exceptions\FacebookResponseException $e) { return 'Graph returned an error: ' . $e->getMessage(); exit; } catch (Facebook\Exceptions\FacebookSDKException $e) { return 'Facebook SDK returned an error: ' . $e->getMessage(); exit; } $user = $response->getGraphUser(); return $user; //return $return; }
/** * @Method({"POST"}) * @Route("/facebook/login", name="facebook_login") */ public function facebookLoginAction(Request $request) { $code = $request->get('code'); $fb = new \Facebook\Facebook(['app_id' => '529276757135612', 'app_secret' => '0fe34b757c10440e7259665a53dda55a', 'default_graph_version' => 'v2.5']); try { $accessToken = $fb->getOAuth2Client()->getAccessTokenFromCode($code, 'http://api.viettut.com/'); $response = $fb->get('/me?fields=id,name,email', $accessToken->getValue()); $user = $response->getGraphUser(); $userManager = $this->container->get('viettut_user.domain_manager.lecturer'); $lecturer = $userManager->findUserByUsernameOrEmail($user['email']); if ($lecturer instanceof UserInterface) { $lecturer->setFacebookId($user['id'])->setName($user['name']); } else { $userDiscriminator = $this->get('rollerworks_multi_user.user_discriminator'); $userDiscriminator->setCurrentUser('viettut_user_system_lecturer'); $lecturer = $userManager->createNew(); $lecturer->setEnabled(true)->setFacebookId($user['id'])->setPlainPassword($user['email'])->setUsername($user['email'])->setEmail($user['email'])->setName($user['name'])->setActive(true)->setAvatar(sprintf('https://graph.facebook.com/%s/picture?type=square', $user['id'])); $userManager->save($lecturer); } $jwtManager = $this->get('lexik_jwt_authentication.jwt_manager'); $jwtTransformer = $this->get('viettut_api.service.jwt_response_transformer'); $tokenString = $jwtManager->create($lecturer); return JsonResponse::create($jwtTransformer->transform(['token' => $tokenString], $lecturer), 200); } catch (\Facebook\Exceptions\FacebookResponseException $e) { throw new UnauthorizedHttpException('Can not login with that account'); } catch (\Facebook\Exceptions\FacebookSDKException $e) { throw new UnauthorizedHttpException('Can not login with that account'); } }
private function get_facebook_credentials($fbToken) { $settings = array('app_id' => APP_ID_FOR_ADS_MANAGER, 'app_secret' => APP_SECRET_FOR_ADS_MANAGER, 'default_graph_version' => 'v2.5'); $fb = new Facebook\Facebook($settings); $fb->setDefaultAccessToken($fbToken); return $fb; }
public function loginAction() { $fb = new \Facebook\Facebook(['app_id' => "{$this->ecommerce_options->facebook_appId}", 'app_secret' => "{$this->ecommerce_options->facebook_appSecret}", 'default_graph_version' => 'v2.4']); $helper = $fb->getRedirectLoginHelper(); $permissions = ['email']; $loginUrl = $helper->getLoginUrl("{$this->ecommerce_options->url_base}user/callback", $permissions); $this->view->facebook = htmlspecialchars($loginUrl); if ($this->request->isPost()) { $email = $this->request->getPost('email'); $senha = $this->request->getPost('senha'); $user = Usuarios::findFirst("email = '{$email}' and nivel_id = 3"); if ($user) { if ($this->security->checkHash($senha, $user->senha)) { $this->setSession($user); if ($this->session->has('checkout')) { $this->session->remove('checkout'); return $this->response->redirect("checkout"); } else { $this->dispatcher->forward(array("action" => "index")); } } else { $this->flashSession->error("Senha Invalida"); return $this->response->redirect("user/login"); } } else { $this->flashSession->error("Nenhum usuario encontrado com o e-mail"); return $this->response->redirect("user/login"); } } }
/** * return true if the current user is a member of $group. here $group will only ever be 'site-planning', but if * multiple groups where defined it would be important to distinguish * @param string $group always 'site-planning' * @return boolean */ function isMemberOf($group) { if (Core::Client()->isAdmin()) { return true; } //TODO: // load fb api. // get token from stored FacebookPlugin parameters // // -- token should have been set up with extended access to user who is an admin of the group -- // // -- for group: fb-admin check //.../{group}/admins // -- for group: fb-member check //../{group}/members // // $fbPlugin = Core::LoadPlugin('FacebookPage'); include_once $fbPlugin->getPath() . DS . 'vendor' . DS . 'autoload.php'; $db = Core::GetDatasource(); $prfx = $db->getPrefix(); $uid = Core::Client()->getUserId(); $results = $db->query('SELECT provider_uid FROM ' . $prfx . 'users_authentications WHERE user_id=' . $uid . ' AND provider=\'facebook\''); if (empty($results)) { return false; } $fbuid = $results[0]->provider_uid; // the following credentials will need to be set. // do not publish the source with real credentials or someone could hijack // the facebook group $app_id = '*****'; $app_secret = '*****'; $app_token = '*****'; $group_id = '*****'; $fb = new Facebook\Facebook(array('app_id' => $app_id, 'app_secret' => $app_secret, 'default_graph_version' => 'v2.5')); $accessToken = $app_token; $fbGroupId = $group_id; $response = $fb->get('/' . $fbGroupId . '/members', $accessToken); $data = json_decode($response->getBody()); //->data; $members = $data->data; while (key_exists('paging', $data) && key_exists('next', $data->paging)) { // facebook group member list might include paging. combine all pages. $text = file_get_contents($data->paging->next); $data = json_decode($text); $members = array_merge($members, $data->data); } foreach ($members as $member) { if ($member->id == $fbuid) { if ($group == "fb-admin") { if ($member->administrator) { return true; } return false; } return true; } } //print_r(array($fbuid,$members)); return false; }
/** * Create an instance of Facebook session */ private function set_fb_request_session() { $settings = array('app_id' => APP_ID_FOR_ADS_MANAGER, 'app_secret' => APP_SECRET_FOR_ADS_MANAGER, 'default_graph_version' => 'v2.5'); $fb = new Facebook\Facebook($settings); $fb->setDefaultAccessToken(self::$fbToken); self::$fbSession = $fb; Api::init(APP_ID_FOR_ADS_MANAGER, APP_SECRET_FOR_ADS_MANAGER, self::$fbToken); }
function fbLogin() { $fb = new Facebook\Facebook(['app_id' => '891873217566556', 'app_secret' => '08f6ae455049a42ee0b31952cb813368', 'default_graph_version' => 'v2.4']); $helper = $fb->getRedirectLoginHelper(); $permissions = ['email']; // Optional permissions $loginUrl = $helper->getLoginUrl('https://localhost/fb-callback.php', $permissions); echo '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>'; }
public function get_facebook_url($callback_url) { $fb = new Facebook\Facebook(['app_id' => '1509104876060790', 'app_secret' => '977e891176e8e1e9e6b626323f01d8bb', 'default_graph_version' => 'v2.5']); $helper = $fb->getRedirectLoginHelper(); $permissions = ['email', 'user_likes', 'pages_show_list']; // optional $loginUrl = $helper->getLoginUrl(base_url() . $callback_url, $permissions); return $loginUrl; }
public function insertAction($args) { require_once __DIR__ . '/facebook-php-sdk-v4-5.0.0/src/Facebook/autoload.php'; $fb = new Facebook\Facebook(['app_id' => '959119600818575', 'app_secret' => '9f0062f110ea6d3589e7debcb04c2268', 'default_graph_version' => 'v2.5']); $userId = $_GET['userId']; $lastName = $_GET['lastName']; $firstName = $_GET['firstName']; $token = $_GET['token']; $var = $fb->get('/me?fields=picture, albums', $token); $obj = $var->getGraphNode(); $picture = $obj['picture']; $photo = $picture['url']; $roles = $fb->get('/959119600818575/roles', '959119600818575|NrwTVp41hp0a8XVklYVvKLOKAzE'); $response = $roles->getGraphEdge(); //On vérifie si il est admin ou pas foreach ($response as $data) { if ($userId == $data['user']) { $_SESSION["role"] = "admin"; $_SESSION["name"] = $firstName . " " . $lastName; $_SESSION["idUser"] = $userId; $_SESSION["photo"] = $photo; $_SESSION["token"] = $token; header('Location: /contest'); exit; } } //On liste les user inscrits $verif = $db->prepare("SELECT id_member FROM member"); $verif->execute(); $result = $verif->fetchAll(PDO::FETCH_ASSOC); //Si le tableau est vide on enregistre le user if (count($result) == 0) { $_SESSION["role"] = "user"; $_SESSION["name"] = $firstName . " " . $lastName; $_SESSION["idUser"] = $userId; $_SESSION["photo"] = $photo; $insertUser = $db->prepare("INSERT INTO member(id_member, lastname, firstname, picture) VALUES ('" . $userId . "','" . $lastName . "','" . $firstName . "','" . $photo . "')"); $insertUser->execute(); header('Location: /contest'); } //On parcoure le tableau foreach ($result as $count) { $_SESSION["role"] = "user"; $_SESSION["name"] = $firstName . " " . $lastName; $_SESSION["idUser"] = $userId; $_SESSION["photo"] = $photo; if ($userId != $count['id_member']) { //echo "on enregistre" $insertUser = $db->prepare("INSERT INTO member(id_member, lastname, firstname, picture) VALUES ('" . $userId . "','" . $lastName . "','" . $firstName . "','" . $photo . "')"); $insertUser->execute(); header('Location: /contest'); } else { //echo "on enregistre pas<br>"; header('Location: /contest'); } } }
public static function getEntriesByTimeline() { //Start - get all timelines from the database $sql = rex_sql::factory(); $timelines = $sql->getArray('SELECT `user_id` FROM `' . rex::getTablePrefix() . 'socialhub_facebook_timeline`'); unset($sql); if (empty($timelines)) { return false; } //End - get all timelines from the database //Start - get all accounts from the database $sql = rex_sql::factory(); $accounts = $sql->getArray('SELECT * FROM `' . rex::getTablePrefix() . 'socialhub_facebook_account` ORDER BY `id` ASC'); unset($sql); if (empty($accounts)) { return false; } //End - get all accounts from the database //Start - get entries by timeline from twitter foreach ($timelines as $timeline) { $fb = new Facebook\Facebook(['app_id' => $accounts[0]['app_id'], 'app_secret' => $accounts[0]['app_secret'], 'default_graph_version' => 'v2.5', 'default_access_token' => $accounts[0]['app_id'] . '|' . $accounts[0]['app_secret']]); try { $response = $fb->get('/' . $timeline['user_id'] . '/posts'); } catch (Facebook\Exceptions\FacebookResponseException $e) { echo rex_view::error('Graph returned an error: ' . $e->getMessage()); } catch (Facebook\Exceptions\FacebookSDKException $e) { echo rex_view::error('Facebook SDK returned an error: ' . $e->getMessage()); } if (empty($response)) { return; } $response = json_decode($response->getBody(), true); foreach ($response['data'] as $post) { list($userID, $postID) = explode('_', $post['id']); $newPost = rex_sql::factory(); $newPost->setTable(rex::getTablePrefix() . 'socialhub_entry_timeline'); $newPost->setWhere(['post_id' => $postID]); $newPost->select(); if ($newPost->getRows() === 0) { $newPost->reset(); $newPost->setTable(rex::getTablePrefix() . 'socialhub_entry_timeline'); $newPost->setValue('source', 'facebook'); $newPost->setValue('post_id', $postID); $newPost->setValue('message', $post['message']); $newPost->setValue('author_id', $userID); $newPost->setValue('created_time', date('Y-m-d H:i:s', strtotime($post['created_time']))); $newPost->setValue('query', '/' . $timeline['user_id'] . '/posts'); try { $newPost->insert(); } catch (rex_sql_exception $e) { echo rex_view::warning($e->getMessage()); } } } } //End - get entries by timeline from twitter }
public function fbtest() { $fb = new Facebook\Facebook(['app_id' => $_ENV['app_id'], 'app_secret' => Hash::make($_ENV['app-secret']), 'default_graph_version' => 'v2.2']); $helper = $fb->getRedirectLoginHelper(); $permissions = ['email']; // Optional permissions $loginUrl = $helper->getLoginUrl('https://example.com/fb-callback.php', $permissions); echo '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>'; }
public function index() { $fb = new Facebook\Facebook(['app_id' => '1537802373177371', 'app_secret' => '6fa5147d3d86aede88b266ba23065911', 'default_graph_version' => 'v2.2']); $helper = $fb->getRedirectLoginHelper(); $permissions = ['email']; $loginUrl = $helper->getLoginUrl('https://learnfacebooksignin.dev/auth/facebook/callback', $permissions); $data = ['loginUrl' => $loginUrl]; $this->load->view('auth/login', $data); }
public function index_get() { $this->load->view('friendsfair_view'); $fb = new Facebook\Facebook(['app_id' => '1009973879053286', 'app_secret' => '0822af5ebcae25a7cdc27412fb029855', 'default_graph_version' => 'v2.4']); $helper = $fb->getRedirectLoginHelper(); $permissions = ['email']; // Optional permissions $scope = ['email', 'user_likes', 'email', 'public_profile']; $loginUrl = $helper->getLoginUrl('http://staging.vpc.viral9.com/login_page/facebook_redirect_handler', $scope); print_r($loginUrl); }
function Login() { session_start(); require_once __DIR__ . '/facebook-php-sdk-v4-5.0-dev/src/Facebook/autoload.php'; $fb = new Facebook\Facebook(['app_id' => APP_ID, 'app_secret' => APP_SECRET, 'default_graph_version' => 'v2.3']); $helper = $fb->getRedirectLoginHelper(); $permissions = ['email']; // Optional permissions $loginUrl = $helper->getLoginUrl('http://localhost/connect2015/signup.php', $permissions); echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>'; }
function GenerateLoginLink() { $config = (include "/config.php"); $fb = new Facebook\Facebook(['app_id' => $config['app_id'], 'app_secret' => $config['app_secret'], 'default_graph_version' => 'v2.4']); $helper = $fb->getRedirectLoginHelper(); $permissions = array(); foreach (explode(',', $config['facebook_permissions']) as $v) { array_push($permissions, $v); } $loginUrl = $helper->getLoginUrl($config['domain'] . '/facebook/login/success', $permissions); return $loginUrl; //echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>'; }
public function me() { $fb = new \Facebook\Facebook(['app_id' => $this->appId, 'app_secret' => $this->appSecret, 'default_graph_version' => 'v2.5']); $token = $this->session->getToken(); $response = $fb->get('/me?locale=en_US&fields=gender,last_name,email,first_name,verified', $token); $userNode = $response->getGraphNode(); $email = $userNode->getField('email'); $name = $userNode->getField('last_name'); $firstname = $userNode->getField('first_name'); $gender = $userNode->getField('gender'); $verified = $userNode->getField('verified'); $id = $userNode->getField('id'); $this->session->setGender($gender)->setVerified($verified)->setName($name)->setFirstname($firstname)->setEmail($email)->setId($id); }
public function data() { $config = new Controllers_Api_Facebook_Config_App(); $fb = new Facebook\Facebook(['app_id' => $config->config['app_id'], 'app_secret' => $config->config['app_secret'], 'default_graph_version' => $config->config['default_graph_version']]); $helper = $fb->getRedirectLoginHelper(); $result = array(); try { $accessToken = $helper->getAccessToken(); if (!isset($accessToken)) { if ($helper->getError()) { $result = array('status' => false, 'error' => $helper->getError(), 'code' => $helper->getErrorCode(), 'reason' => $helper->getErrorReason(), 'description' => $helper->getErrorDescription()); } else { $result = array('status' => false, 'error' => 'Bad request'); } } else { $oAuth2Client = $fb->getOAuth2Client(); // Get the access token metadata from /debug_token $tokenMetadata = $oAuth2Client->debugToken($accessToken); $expired = $tokenMetadata->metadata['expires_at']; $issued = $tokenMetadata->metadata['issued_at']; $result['status'] = true; $result['data']['token'] = $tokenMetadata; //session 2 try { // Returns a `Facebook\FacebookResponse` object $response = $fb->get('/me?fields=id,name,email', $accessToken->getValue()); $user = json_decode($response->getGraphUser()); $result['data']['user'] = $user; } catch (Facebook\Exceptions\FacebookResponseException $e) { $result['data']['user'] = $e->getMessage(); } catch (Facebook\Exceptions\FacebookSDKException $e) { $result['data']['user'] = $e->getMessage(); } } } catch (Facebook\Exceptions\FacebookResponseException $e) { // When Graph returns an error $result = array('status' => false, 'error' => $e->getMessage()); } catch (Facebook\Exceptions\FacebookSDKException $e) { // When validation fails or other local issues $result = array('status' => false, 'error' => $e->getMessage()); } $result['social'] = 'facebook'; //$redirect_uri = $this->input->get('redirect_uri'); //if(isset($_GET['code'])){ // header("Location: ".$redirect_uri."?".http_build_query($result, '', '&')); // }else{ echo json_encode($result); // } }
function login_callback() { $fb = new \Facebook\Facebook(['app_id' => FB_APP_ID, 'app_secret' => FB_SECRET_KEY]); $helper = $fb->getRedirectLoginHelper(); try { $access_token = $helper->getAccessToken(); } catch (Facebook\Exceptions\FacebookResponseException $e) { echo 'Graph return an error: ' . $e->getMessage(); exit; } catch (Facebook\Exceptions\FacebookSDKException $e) { echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit; } if (!isset($access_token)) { if ($helper->getError()) { header('HTTP/1.0 401 Unauthorized'); echo "Error: " . $helper->getError() . "\n"; echo "Error Code: " . $helper->getErrorCode() . "\n"; echo "Error Reason: " . $helper->getErrorReason() . "\n"; echo "Error Description: " . $helper->getErrorDescription() . "\n"; } else { header('HTTP/1.0 400 Bad Request'); echo 'Bad request'; } exit; } $oAuth2Client = $fb->getOAuth2Client(); $tokenMetaData = $oAuth2Client->debugToken($access_token); $tokenMetaData->validateAppId(FB_APP_ID); $tokenMetaData->validateExpiration(); if (!$access_token->isLongLived()) { try { $access_token = $oAuth2Client->getLongLivedAccessToken($access_token); } catch (Facebook\Exceptions\FacebookSDKException $e) { echo "<p>Error getting long-lived access token: " . $e->getMessage() . "</p>"; exit; } } $facebook_access_token = (string) $access_token; $this->load->model('api_model'); $facebook_user = $this->api_model->facebook_get_user($facebook_access_token); $user_account = array('user_id' => $this->user->id, 'account_id' => $facebook_user['id'], 'type' => 'facebook', 'access_token' => $facebook_access_token); $this->load->model('user_account_model'); if ($this->user_account_model->save($user_account)) { $_SESSION['facebook_access_token'] = $facebook_access_token; $this->session->set_userdata('facebook_access_token', $facebook_access_token); redirect(base_url() . "main/myaccount/facebook"); } }
function download_album($accessToken, $album_download_directory, $album_id, $album_name) { $fb = new Facebook\Facebook(['app_id' => APPID, 'app_secret' => APPSECRET, 'default_graph_version' => 'v2.4']); $response = $fb->get('/' . $album_id . '/photos?fields=source', $accessToken); $album_photos = $response->getDecodedBody(); $album_directory = $album_download_directory . $album_name; if (!file_exists($album_directory)) { mkdir($album_directory, 0777); } $i = 1; foreach ($album_photos['data'] as $album_photo) { file_put_contents($album_directory . '/' . $i . ".jpg", fopen($album_photo['source'], 'r')); $i++; } }
public static function facebook($url, $content) { $content = html_entity_decode($content); require_once addons . 'lib/SocialNetwork/facebook-php-sdk/src/Facebook/autoload.php'; $fb = new \Facebook\Facebook(['app_id' => '__app_id', 'app_secret' => '__app_secret', 'default_graph_version' => 'v2.4']); $linkData = ['message' => $content, 'link' => $url]; try { $response = $fb->post('/url/feed', $linkData, '__token_'); } catch (\Facebook\Exceptions\FacebookResponseException $e) { return 'Graph returned an error: ' . $e->getMessage(); } catch (\Facebook\Exceptions\FacebookSDKException $e) { return 'Facebook SDK returned an error: ' . $e->getMessage(); } $graphNode = $response->getGraphNode(); return $graphNode['id']; }
/** * Checks with the site to confirm that the given token is indeed valid * and corresponds with the userID we were given. It can do anything else * it needs as well (e.g. facebook provides a debug_token endpoint) * * @param string $token * @param string $userID * @return boolean */ public function validateToken($token, $userID) { $fb = new Facebook\Facebook(['app_id' => Config::inst()->get('FacebookApi', 'AppID'), 'app_secret' => Config::inst()->get('FacebookApi', 'AppSecret'), 'default_graph_version' => 'v2.2']); try { // Returns a `Facebook\FacebookResponse` object $response = $fb->get('/me?fields=id,name', $token); } catch (Facebook\Exceptions\FacebookResponseException $e) { SS_Log::log("Graph returned an error: " . $e->getMessage(), SS_Log::INFO); return false; } catch (Facebook\Exceptions\FacebookSDKException $e) { SS_Log::log('Facebook SDK returned an error: ' . $e->getMessage(), SS_Log::WARN); return false; } $user = $response->getGraphUser(); return $user->getId() == $userID; }
public static function getListFeeds($fb_id, $limit) { $fb = new \Facebook\Facebook(['app_id' => FACEBOOK_API_KEY, 'app_secret' => FACEBOOK_API_SECRET, 'default_graph_version' => 'v2.5']); $request = new \Facebook\FacebookRequest(self::fbApp(), $_SESSION['facebook_access_token'], 'GET', '/' . $fb_id . '/feed', array('fields' => 'admin_creator,created_time,description,from,name,message,link,comments.limit(1).summary(true),likes.limit(1).summary(true)', 'limit' => $limit)); $response = $fb->getClient()->sendRequest($request); $graphObject = $response->getDecodedBody()['data']; $fbData = []; $i = 1; foreach ($graphObject as $key => $object) { $createdDate = $object['created_time']; $date_arr = explode('T', $createdDate); $fbData[] = ['id' => $object['id'], 'from' => $object['from']['name'], 'link' => isset($object['link']) ? $object['link'] : '', 'name' => isset($object['name']) ? $object['name'] : '', 'description' => isset($object['description']) ? $object['description'] : '', 'message' => isset($object['message']) ? $object['message'] : '', 'date' => $date_arr[0], 'time' => $date_arr[1], 'comments' => isset($object['comments']['summary']['total_count']) ? $object['comments']['summary']['total_count'] : 0, 'likes' => isset($object['likes']['summary']['total_count']) ? $object['likes']['summary']['total_count'] : 0]; $i++; } return $fbData; }
public static function post($event_id) { if (isset($event_id)) { try { $event = Event::findOrFail($event_id); $fb = new \Facebook\Facebook(['app_id' => getenv('FACEBOOK_APP_ID'), 'app_secret' => getenv('FACEBOOK_APP_SECRET'), 'default_graph_version' => 'v2.4', 'default_access_token' => getenv('FACEBOOK_PAGE_TOKEN')]); $fbPageId = getenv('FACEBOOK_PAGE_ID'); $sourceLink = "https://relive.space/event/" . $event->event_id; $fbPostMessage = "The event \"" . $event->eventName . "\" was just added to relive.space!\n\n" . $sourceLink; $response = $fb->post('/' . $fbPageId . '/feed', ['message' => $fbPostMessage]); echo json_encode($response); } catch (ModelNotFoundException $e) { echo "event " . $event_id . " not found!"; } } }
public function get() { $config = new Controllers_Api_Facebook_Config_App(); $redirect_uri = $this->input->get('redirect_uri') ? $this->input->get('redirect_uri') : ''; $fb = new Facebook\Facebook(['app_id' => $config->config['app_id'], 'app_secret' => $config->config['app_secret'], 'default_graph_version' => $config->config['default_graph_version']]); $helper = $fb->getRedirectLoginHelper(); $permissions = ['email', 'user_likes', 'publish_actions', 'public_profile', 'user_friends']; // optional $call_back = $this->config->get('domain') . 'api/facebook/callback/data'; $loginUrl = $helper->getLoginUrl($call_back, $permissions); if ($this->input->get('test')) { echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>'; } else { echo json_encode(array('status' => true, 'url' => $loginUrl)); } }
function output_widget($region, $place, $themeobject, $template, $request, $qa_content) { require_once QA_INCLUDE_DIR . 'qa-app-users.php'; $allowEdit = !qa_user_permit_error('fb_share_permit_edit'); $parts = explode('/', qa_self_html()); if ($allowEdit && $parts[2] == qa_get_logged_in_handle()) { $appid = qa_opt('fb_app_id'); $secret = qa_opt('fb_app_secret'); $fb = new Facebook\Facebook(['app_id' => $appid, 'app_secret' => $secret, 'default_graph_version' => 'v2.4']); $helper = $fb->getRedirectLoginHelper(); $permissions = ['email', 'publish_actions']; $callback = 'http://nathorr.com/qeta/fb-share/' . qa_get_logged_in_handle() . '/'; $loginUrl = $helper->getLoginUrl($callback, $permissions); echo '<a href="' . $loginUrl . '"><img src="http://oi57.tinypic.com/f1xlbt.jpg"></a>'; } }
public function postStatus($status) { $fb = new Facebook\Facebook(['app_id' => $this->_appID, 'app_secret' => $this->_appSecret, 'default_graph_version' => $this->_defaultGraphVersion]); try { // Post to https://www.facebook.com/bcs.kpasapp $response = $fb->post('/me/feed', $status, $this->_accessToken); // Post to https://www.facebook.com/master.kpasapp/ $response2 = $fb->post('/633059556824338/feed', $status, $this->_pageAccessToken); // Post to https://www.facebook.com/groups/eventsbcs/ $response3 = $fb->post('/723256584381647/feed', $status, $this->_accessToken); // Post to https://www.facebook.com/groups/1415807262056337/ $response4 = $fb->post('/1415807262056337/feed', $status, $this->_accessToken); } catch (Facebook\Exceptions\FacebookResponseException $e) { echo 'Graph returned an error: ' . $e->getMessage(); } catch (Facebook\Exceptions\FacebookSDKException $e) { echo 'Facebook SDK returned an error: ' . $e->getMessage(); } }
function checklogin() { session_start(); if (isset($_SESSION['fb_access_token'])) { require_once __DIR__ . "/facebook-php-sdk-v4/src/Facebook/autoload.php"; require __DIR__ . "/../config/config.php"; $fb = new Facebook\Facebook(['app_id' => $config['facebook']['app_id'], 'app_secret' => $config['facebook']['app_secret'], 'default_graph_version' => 'v2.5']); try { $response = $fb->get('/me', $_SESSION['fb_access_token'])->getDecodedBody(); } catch (Facebook\Exceptions\FacebookResponseException $e) { // echo 'Graph returned an error: ' . $e->getMessage(); } catch (Facebook\Exceptions\FacebookSDKException $e) { // echo 'Facebook SDK returned an error: ' . $e->getMessage(); } return $response; } else { return false; } }