本文整理汇总了PHP中Facebook::api方法的典型用法代码示例。如果您正苦于以下问题:PHP Facebook::api方法的具体用法?PHP Facebook::api怎么用?PHP Facebook::api使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook
的用法示例。
在下文中一共展示了Facebook::api方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: facebook
function facebook()
{
global $template;
$facebook = new Facebook(array('appId' => FB_APPID, 'secret' => FB_APPSECRET));
$user = $facebook->getUser();
if ($user) {
try {
$pages = $facebook->api('/me/accounts');
$template->set('pages', $pages);
$permissions = $facebook->api("/me/permissions");
$publish_actions = 0;
$manage_pages = 0;
foreach ($permissions['data'] as $permission) {
if ($permission['permission'] == 'publish_actions') {
$publish_actions = 1;
}
if ($permission['permission'] == 'manage_pages') {
$manage_pages = 1;
}
}
if ($publish_actions == 0 || $manage_pages == 0) {
throw new Exception("Oops");
}
} catch (Exception $e) {
$url = $facebook->getLoginUrl(array("scope" => "publish_actions,manage_pages"));
header("Location: " . $url);
exit;
}
} else {
$url = $facebook->getLoginUrl(array("scope" => "publish_actions,manage_pages"));
header("Location: " . $url);
exit;
}
}
示例2: postar
public function postar($dados, $usuario)
{
require 'complements/facebook/Facebook.php';
$facebook = new Facebook(array('appId' => '1651517385125370', 'secret' => '84b4334e3cfe153b5a4348407709cbf0'));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
echo "teste";
exit;
$page_id = $usuario;
$page_info = $facebook->api("/{$page_id}?fields=access_token");
if (!empty($page_info['access_token'])) {
$args = array('access_token' => $page_info['access_token'], 'message' => $dados[texto]);
$post_id = $facebook->api("/{$page_id}/feed", "post", $args);
} else {
$permissions = $facebook->api("/me/permissions");
if (!array_key_exists('publish_stream', $permissions['data'][0]) || !array_key_exists('manage_pages', $permissions['data'][0])) {
// We don't have one of the permissions
// Alert the admin or ask for the permission!
header("Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream, manage_pages")));
}
}
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array('scope' => 'manage_pages,publish_stream'));
}
}
示例3: mx_mntestusers
function mx_mntestusers($page, $option, $action)
{
global $facebook;
echo 'Disabled.';
return;
$fbapp = new Facebook(array('appId' => FACEBOOK_APP_ID, 'secret' => FACEBOOK_SECRET, 'grant_type' => 'client_credentials'));
$acctok = $fbapp->getAccessToken();
if ($_REQUEST['createuser']) {
$newuser = $fbapp->api('/' . FACEBOOK_APP_ID . '/accounts/test-users?installed=true&permissions=&access_token=' . $acctok, 'POST');
} else {
if ($_REQUEST['deleteuser']) {
foreach ($_REQUEST['selected'] as $user) {
$testusers = $fbapp->api('/' . $user . '?access_token=' . $acctok, 'DELETE');
mx_deleteuser($user);
// delete should only be possible for test users!!
}
}
}
$testusers = $fbapp->api('/' . FACEBOOK_APP_ID . '/accounts/test-users&access_token=' . $acctok, 'GET');
echo '<form action="' . mx_optionurl($page, $option) . '" method=POST>';
echo '<table border=1 width=100%><tr><th>Sel</th><th>ID</th><!-- <th>access_token</th> --><th>login_url</th></tr>';
foreach ($testusers['data'] as $testuser) {
echo '<tr><td><input type=checkbox name="selected[]" value="' . $testuser['id'] . '"></td>' . '<td>' . $testuser['id'] . '</td>';
//$user=$facebook->api('/'.$testuser['id']);
//die(print_r($user));
//echo '<td>'.$user['name'].'</td>';
echo '<!-- <td>' . $testuser['access_token'] . '</td> --><td>' . '<a href="' . $testuser['login_url'] . '">' . $testuser['login_url'] . '</a></td></tr>';
}
echo '<tr><td colspan=3 align=center><input type=submit name="createuser" value="Create User">' . ' <input type=submit name="deleteuser" value="Delete User(s)"></td></tr>';
echo '</table></form>';
}
示例4: loadUserByUsername
public function loadUserByUsername($username)
{
$user = $this->findUserByFbId($username);
try {
$fbdata = $this->facebook->api('/me');
} catch (FacebookApiException $e) {
$fbdata = null;
}
if (!empty($fbdata)) {
if (empty($user)) {
if (!isset($fbdata['email']) || $fbdata['email'] == '') {
// TODO: the user was found obviously, but doesnt match our expectations, do something smart
throw new UsernameNotFoundException('Une erreur est survenue lors de votre connexion...');
}
$user = $this->userManager->createUser();
$user->setEnabled(true);
$user->setPassword('');
}
if ($user->getUsername() == '' || $user->getUsername() == null) {
$user->setUsername($username . '@facebook.com');
}
$user->setFBData($fbdata);
if (count($this->validator->validate($user, 'Facebook'))) {
// TODO: the user was found obviously, but doesnt match our expectations, do something smart
throw new UsernameNotFoundException('Une erreur est survenue lors de votre connexion...');
}
$this->userManager->updateUser($user);
}
if (empty($user)) {
// TODO: the user was found obviously, but doesnt match our expectations, do something smart
throw new UsernameNotFoundException('Une erreur est survenue lors de votre connexion...');
}
return $user;
}
示例5: Facebook
function try_connect($pubit = 0, $stUrl = '', $PublishMessage = '')
{
$myparams =& JComponentHelper::getParams('com_fbjconnect');
$getappid = $myparams->get('appid');
$getappsec = $myparams->get('appsecret');
$access_token = "";
$uid = "";
$postresult = false;
$facebook = new Facebook(array('appId' => $getappid, 'secret' => $getappsec, 'cookie' => true));
$session = $facebook->getSession();
$me = null;
$uid = "";
if ($session) {
try {
$access_token = $facebook->getAccessToken();
$me = $facebook->api('/me');
$uid = $facebook->getUser();
if ($pubit == 1) {
$fbpic = JURI::base() . 'modules/mod_jfbgconnect/fgimage.jpg';
$postresult = $facebook->api('/me/feed/', 'post', array('access_token' => $access_token, 'picture' => $fbpic, 'link' => $stUrl, 'message' => $PublishMessage));
}
} catch (FacebookApiException $e) {
error_log($e);
}
}
return array($uid, $me, $session, $access_token, $postresult);
}
示例6: postFacebook
/**
* @todo fix this BIG mess.
*/
public static function postFacebook($message, $link = null, $impression = null)
{
$member = Member::currentUser();
$postresult = false;
$SiteConfig = SiteConfig::current_site_config();
if ($member && $SiteConfig->FBAppID && $SiteConfig->FBSecret) {
if ($link == null) {
$link = Director::absoluteBaseURL();
}
$page = '/' . $SiteConfig->FBPageID . '/feed';
$facebook = new Facebook(array('appId' => $SiteConfig->FBAppID, 'secret' => $SiteConfig->FBSecret));
$token = $facebook->api('/me/accounts');
foreach ($token['data'] as $pages) {
if ($pages['id'] == $SiteConfig->FBPageID) {
$facebook->setAccessToken($pages['access_token']);
$verified = true;
break;
}
}
if ($verified) {
$data = array('message' => $message, 'link' => $link, 'picture' => $impression);
$postresult = $facebook->api($page, 'post', $data);
}
}
return $postresult;
}
示例7: loadUserByUsername
public function loadUserByUsername($username)
{
$user = $this->findUserByFbId($username);
try {
$fbdata = $this->facebook->api('/me');
} catch (FacebookApiException $e) {
$fbdata = null;
}
if (!empty($fbdata)) {
if (empty($user)) {
$user = $this->userManager->createUser();
$user->setEnabled(true);
$user->setPassword('');
}
// TODO use http://developers.facebook.com/docs/api/realtime
$user->setFBData($fbdata);
if (count($this->validator->validate($user, 'Facebook'))) {
// TODO: the user was found obviously, but doesnt match our expectations, do something smart
throw new UsernameNotFoundException('The facebook user could not be stored');
}
$this->userManager->updateUser($user);
}
if (empty($user)) {
throw new UsernameNotFoundException('The user is not authenticated on facebook');
}
return $user;
}
示例8: getApiUser
/**
* Returns the api user
*
* @return ApiUser|null
*/
public function getApiUser()
{
try {
$me = $this->facebook->api('/me');
return new ApiUser($me);
} catch (\Exception $e) {
return null;
}
}
示例9: getFeed
public function getFeed($options)
{
if (empty($options['sa_fb_app_id']) && empty($options['sa_fb_app_secret'])) {
return array('error' => 2, 'message' => 'Facebook App ID and/or secret not set. Please set this in the settings page.');
}
$facebook = new Facebook(array('appId' => $options['sa_fb_app_id'], 'secret' => $options['sa_fb_app_secret']));
if (empty($options['sa_fb_page_id'])) {
return array('error' => 2, 'message' => 'Facebook Page ID not set.');
}
$since_time = empty($options['sa_since_time']) ? 1 : $options['sa_since_time'];
try {
// $user_profile = $facebook->api('/me');
// $this->log($user_profile);
$response = $facebook->api($options['sa_fb_page_id'] . '/feed/?fields=id,type,caption,picture,message,link,object_id&limit=25&since=' . $since_time);
} catch (FacebookApiException $e) {
// $loginUrl = $facebook->getLoginUrl(array('scope' => 'publish_stream', 'redirect_uri' => 'http://freefly.ryan.invokedev.com/'));
$result = $e->getResult();
return array('error' => 4, 'message' => 'Error fetching Facebook feed: <span class="social-feed-error">' . $result['error']['message'] . '</span>');
// $loginUrl = $facebook->getLoginUrl();
// $user = null;
// echo "<script>top.location.href = '$loginUrl'</script>";
// exit;
}
// return an array with success = false if $response is empty..
if (count($response['data']) == 0) {
return array('error' => 1, 'message' => 'No Facebook items found.');
}
$data = array();
$date_added = time();
$created_times = array(0);
foreach ($response['data'] as $post) {
if ($post['type'] == 'photo') {
// get images..
$images = $facebook->api($post['object_id'] . '?fields=images');
$p = array();
foreach ($images['images'] as $item) {
if ($item['height'] >= 480) {
$p['picture'] = $item['source'];
break;
}
}
$p['id'] = $post['id'];
$p['message'] = empty($post['message']) ? '' : $post['message'];
$p['link'] = empty($post['link']) ? '' : $post['link'];
$p['date_added'] = $date_added;
$created_time = new DateTime($post['created_time']);
$p['date_created'] = $created_time->format('U');
$created_times[] = $created_time->format('U');
array_push($data, $p);
}
}
if (count($data) == 0) {
return array('error' => 3, 'message' => 'No new Facebook items found.');
}
$res = array('data' => $data, 'since_time' => max($created_times));
return $res;
}
示例10: update_facebook_wall
function update_facebook_wall($text)
{
$appId = '101183239949229';
$appSecret = 'fd040afd3af84cc13b6a70ea602b4ca6';
$srcPageId = '116587918401126';
//Use Evan Hsu's access token because he is one of the Page Admins
//**** The access Token will need to be updated whenever Evan changes his Facebook password
$accessToken = 'AAABcBo8TC60BAOJGsdKapdUYfvbBOJm9jc9EHZBZBpD45mAN2poo9t7nfxtII3I7XZAxH9RMuI1AOD2BjWUEyso17nTkNVR2aEGaZC287Vqe8932fjQ9';
$config = array('appId' => $appId, 'secret' => $appSecret);
$facebook = new Facebook($config);
$args = array('access_token' => $accessToken, 'message' => $text);
try {
$post_id = $facebook->api("/{$srcPageId}/feed", "post", $args);
} catch (FacebookApiException $e) {
//If post failed, do nothing. Permission check happens below.
}
if (!$post_id) {
// If the accessToken is no longer valid (Evan changed his password or revoked permissions),
// then someone with admin access to the Siskiyou facebook page will need to be logged in.
$user = $facebook->getUser();
if ($user) {
try {
$page_info = $facebook->api("/{$srcPageId}?fields=access_token");
if (!empty($page_info['access_token'])) {
$args = array('access_token' => $page_info['access_token'], 'message' => $text);
$post_id = $facebook->api("/{$srcPageId}/feed", "post", $args);
//echo "Access Token: ".$page_info['access_token'];
} else {
$permissions = $facebook->api("/me/permissions");
if (!array_key_exists('publish_stream', $permissions['data'][0]) || !array_key_exists('manage_pages', $permissions['data'][0])) {
// We don't have one of the permissions
// Alert the admin or ask for the permission!
header("Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream, manage_pages, offline_access")));
}
}
} catch (FacebookApiException $e) {
//error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array('scope' => 'manage_pages,publish_stream,offline_access'));
header("Location: " . $loginUrl);
}
}
// END if(!$post_id)
if ($post_id != "") {
header('location: http://www.siskiyourappellers.com/current.php');
}
}
示例11: getInput
public function getInput()
{
if ($this->fb->getUser()) {
$user = $this->fb->getUser();
$profile = $this->fb->api("/me?fields=id,name,picture");
$label = "<img src='" . $profile['picture']['data']['url'] . "' />" . $profile['name'];
$logout = $this->fb->getLogoutUrl(array('next' => JURI::base()));
return $label . "<br /><a href='" . $logout . "'>Log out of Facebook</a>";
} else {
// Not logged in - display a login link
$uri = JURI::current();
$loginUrl = $this->fb->getLoginUrl(array('redirect_uri' => "http://aquinas.dphin.co.uk/login/profile?layout=edit"));
return "<a href='" . $loginUrl . "'>Connect your Facebook account</a>";
}
}
示例12: process_request
public function process_request($request)
{
if ($request == 'facebook-login') {
$app_id = qa_opt('facebook_app_id');
$app_secret = qa_opt('facebook_app_secret');
$tourl = qa_get('to');
if (!strlen($tourl)) {
$tourl = qa_path_absolute('');
}
if (strlen($app_id) && strlen($app_secret)) {
require_once $this->directory . 'facebook.php';
$facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));
$fb_userid = $facebook->getUser();
if ($fb_userid) {
try {
$user = $facebook->api('/me?fields=email,name,verified,location,website,about,picture.width(250)');
if (is_array($user)) {
qa_log_in_external_user('facebook', $fb_userid, array('email' => @$user['email'], 'handle' => @$user['name'], 'confirmed' => @$user['verified'], 'name' => @$user['name'], 'location' => @$user['location']['name'], 'website' => @$user['website'], 'about' => @$user['bio'], 'avatar' => strlen(@$user['picture']['data']['url']) ? qa_retrieve_url($user['picture']['data']['url']) : null));
}
} catch (FacebookApiException $e) {
}
} else {
qa_redirect_raw($facebook->getLoginUrl(array('redirect_uri' => $tourl)));
}
}
qa_redirect_raw($tourl);
}
}
示例13: fbes_get_events
function fbes_get_events($fbes_api_key, $fbes_api_secret, $fbes_access_token, $fbes_api_uids)
{
require_once 'facebook-php-sdk/facebook.php';
//modified
$facebook = new Facebook(array('appId' => $fbes_api_key, 'secret' => $fbes_api_secret, 'cookie' => true));
$facebook->setAccessToken($fbes_access_token);
$ret = array();
foreach ($fbes_api_uids as $key => $value) {
if ($value != '') {
$result = $facebook->api('/' . $value . '/events', 'GET', array('fields' => 'name,start_time,end_time,place,description,timezone', 'date_format' => 'U'));
$result = $result['data'];
foreach ($result as $k => $v) {
$result[$k]['uid'] = $value;
$result[$k]['start_time'] = strtotime($result[$k]['start_time']);
$result[$k]['end_time'] = strtotime($result[$k]['end_time']);
if ($result[$k]['place']) {
if ($result[$k]['place']['name']) {
$result[$k]['location'] = $result[$k]['place']['name'];
} else {
$result[$k]['location'] = $result[$k]['place'];
}
}
}
$ret = array_merge($ret, $result);
}
}
return $ret;
}
示例14: indexAction
public function indexAction()
{
// connect to app
$config = array();
$config['appId'] = '1017499418312477';
$config['secret'] = 'b8887afcd0172d566b624ae920065234';
$config['fileUpload'] = false;
// optional
// instantiate
$facebook = new \Facebook($config);
//call the API to retrieve data from facebook
$array = $facebook->api("/feed?ids=lilotregal,649823778452363");
//build a pattern to use it in regex in order to retrieve only menus from the posts
$pattern = '/(repas du|menu du|repas du jour|menu du jour).*(lundi|mardi|mercredi|jeudi|vendredi|samedi|dimanche).*(\\d).*(janvier|février|mars|avril|mai|juin|juillet|août|septembre|octobre|novembre|décembre)/i';
//make a counter to take just the three last menus
$i = 0;
//build an array to store data of the first page
$data = array();
//build an array to retrieve menu's titles to display them in the panel heading
$menuOfdays = array();
foreach ($array["lilotregal"] as $pagefeed) {
foreach ($pagefeed as $page) {
if (isset($page['message']) && isset($page['created_time']) && preg_match($pattern, $page['message'], $matches)) {
$dates = date("Y/m/d", strtotime($page['created_time'] . "+1 day"));
$menuOfdays[$dates] = $matches['0'];
if ($dates == date("Y/m/d")) {
$menuOfdays[$dates] = "Menu d'aujourd'hui";
}
$data[] = $page['message'];
//take only the three last menus
if (++$i === 3) {
break;
}
}
}
}
$menuOfday = array_values($menuOfdays);
$i = 0;
//store the data of the second page
$refine = array();
//build an array to retrieve meal's titles to display them in the panel heading
$mealOfdays = array();
foreach ($array["649823778452363"] as $menus) {
foreach ($menus as $menu) {
if (isset($menu['message']) && isset($menu['created_time']) && preg_match($pattern, $menu['message'], $matches)) {
$dates2 = date("Y/m/d", strtotime($menu['created_time'] . "+1 day"));
$mealOfdays[] = $matches['0'];
if ($dates2 == date("Y/m/d")) {
$mealOfdays['0'] = "Repas d'aujourd'hui";
}
$refine[] = $menu['message'];
//take only the three last meals
if (++$i === 3) {
break;
}
}
}
}
return $this->render('ApplicationApplicationBundle:Default:index.html.twig', array('data' => $data, 'refine' => $refine, 'menuOfday' => $menuOfday, 'mealOfday' => $mealOfdays));
}
示例15: connectFacebook
function connectFacebook()
{
$this->autoRender = false;
$facebook = new Facebook(array('appId' => $this->facebookAppId, 'secret' => $this->facebookSecret));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
$userinfo = $this->User->find('first', array('conditions' => array('User.username' => isset($user_profile['id']) ? $user_profile['id'] : $user_profile['email'], 'User.social_connect' => 'facebook')));
if (empty($userinfo)) {
$data['User']['username'] = isset($user_profile['id']) ? $user_profile['id'] : $user_profile['email'];
$data['User']['password'] = $user_profile['id'];
$data['User']['group_id'] = $this->socialLoginGroupId;
$data['User']['social_connect'] = 'facebook';
$data['User']['social_info'] = json_encode($user_profile);
$this->User->create();
$this->User->save($data);
$userinfo = $this->User->find('first', array('conditions' => array('User.id' => $this->User->id)));
$this->makeUserLogin($userinfo);
} else {
$this->makeUserLogin($userinfo);
}
} catch (Exception $e) {
error_log($e->getMessage());
$this->Session->setFlash($e->getMessage());
$user = NULL;
}
} else {
$this->Session->setFlash('Sorry.Please try again');
}
$this->render('Social/close_window');
}