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


PHP Facebook::setAccessToken方法代码示例

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


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

示例1: resourcePost

function resourcePost($api, $tools, $param)
{
    global $FBArr;
    $param["fbId"] = $tools->sql_injection_anti($_POST["data"]["id"]);
    $_SESSION["fb_{$FBArr['appId']}_access_token"] = $_POST['token'];
    $param["requestIds"] = $tools->sql_injection_anti($_POST["requestIds"]);
    include_once "../../library/Table/Request.class.php";
    $request = new Request();
    include_once LIB_PATH . 'facebook/facebook.php';
    $facebook = new Facebook($FBArr);
    $facebook->setAccessToken($_SESSION["fb_{$FBArr['appId']}_access_token"]);
    $requestData = $facebook->api(array('method' => 'fql.query', 'query' => "SELECT sender_uid FROM apprequest WHERE request_id = '{$param["requestIds"]}'"));
    $param["senderId"] = $requestData[0]["sender_uid"];
    $url = "http://me.molome.tw/game/get_fb_gameacc";
    $key = "WVdFMVpqQTBaVGtPQzAwTkRjMUxUazNN";
    $time = time();
    $sign = md5($param["fbId"] . $time . $key);
    $url = sprintf($url . "?fbid=%s&time=%s&sign=%s", $param["fbId"], $time, $sign);
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
    $result = curl_exec($curl);
    $json = json_decode($result);
    curl_close($curl);
    if ($json->info[0]->name != '' and $json->info[0]->sid != '') {
        $param['join'] = -1;
    } else {
        $param['join'] = 0;
    }
    $url = "http://graph.facebook.com/" . $param['senderId'];
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
    $result = curl_exec($curl);
    $userData = json_decode($result);
    $api->setOutput('新增資料成功', array("sender" => $userData));
    return;
}
开发者ID:aav8dgogogotw,项目名称:2013q4hmr,代码行数:40,代码来源:request.php

示例2: logout

 /**
  * @param string $logoutUrl
  */
 public function logout($logoutUrl = '')
 {
     if (empty($logoutUrl)) {
         $logoutUrl = self::$object->getLogoutUrl(array('next' => self::getRedirectUrl() . '#postJobs'));
     }
     self::$object->setAccessToken('');
     self::$object->destroySession();
     SJB_HelperFunctions::redirect($logoutUrl);
 }
开发者ID:Maxlander,项目名称:shixi,代码行数:12,代码来源:FacebookSocialMedia.php

示例3: 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;
 }
开发者ID:helpfulrobot,项目名称:firesphere-social,代码行数:29,代码来源:FacebookController.php

示例4: sendToSocialMedia

 /**
  *
  * @param array $data
  * @param array $services
  */
 public function sendToSocialMedia(array $data, array $services = array('facebook', 'twitter'))
 {
     // init output
     $ids = array('facebook' => null, 'twitter' => null);
     // Facebook
     if (in_array('facebook', $services) && $this->confirmFacebookAccess()) {
         $facebook = new Facebook(array('appId' => static::$conf->FacebookAppId, 'secret' => static::$conf->FacebookAppSecret));
         $facebook->setAccessToken(static::$conf->FacebookPageAccessToken);
         try {
             $post_id = $facebook->api("/" . static::$conf->FacebookPageId . "/feed", "post", $data);
             $ids['facebook'] = $post_id['id'];
         } catch (FacebookApiException $e) {
             SS_Log::log('Error ' . $e->getCode() . ' : ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage() . "\n" . 'BackTrace: ' . "\n" . $e->getTraceAsString(), SS_Log::ERR);
         }
     }
     // Twitter
     if (in_array('twitter', $services) && $this->confirmTwitterAccess()) {
         $connection = new tmhOAuth(array('consumer_key' => static::$conf->TwitterConsumerKey, 'consumer_secret' => static::$conf->TwitterConsumerSecret, 'user_token' => static::$conf->TwitterOAuthToken, 'user_secret' => static::$conf->TwitterOAuthSecret));
         $tweet = $data['name'] . ": " . $data['link'];
         $code = $connection->request('POST', $connection->url('1.1/statuses/update'), array('status' => $tweet));
         if ($code == 200) {
             $data = json_decode($connection->response['response']);
             $ids['twitter'] = $data->id_str;
         }
     }
     return $ids;
 }
开发者ID:helpfulrobot,项目名称:azt3k-abc-silverstripe-social,代码行数:32,代码来源:PostToSocialMedia.php

示例5: face

 private function face($access_token, $dataConfig)
 {
     require_once 'php-sdk/src/facebook.php';
     $facebook = new Facebook($dataConfig);
     $facebook->setAccessToken($access_token);
     Zend_Debug::dump($user = $facebook->getUser());
     if ($user) {
         $this->view->faceUrl = $facebook->getLogoutUrl();
     } else {
         $this->view->faceUrl = $facebook->getLoginUrl();
     }
     Zend_Debug::dump($_REQUEST);
     Zend_Debug::dump($naitik = $facebook->api('/100000874886897'));
     if ($user) {
         try {
             // Proceed knowing you have a logged in user who's authenticated.
             $user_profile = $facebook->api('/me');
             print_r($user_profile);
         } catch (FacebookApiException $e) {
             error_log($e);
             $user = null;
         }
     }
     $this->view->user = $naitik;
 }
开发者ID:raphaeldealmeida,项目名称:Demagogos,代码行数:25,代码来源:IndexController.php

示例6: facebook_init

function facebook_init()
{
    require 'src/facebook.php';
    global $facebook;
    $facebook = new Facebook(array('appId' => FB_KEY, 'secret' => FB_SECRET));
    if (!empty($_SESSION) && !empty($_SESSION['fb_code'])) {
        $url = "https://graph.facebook.com/oauth/access_token?";
        $params = array();
        $params[] = 'client_id=' . $facebook->getAppId();
        $params[] = 'redirect_uri=' . 'http://' . HOST . get_url('/facebook/auth/');
        $params[] = 'client_secret=' . $facebook->getApiSecret();
        $params[] = 'code=' . $_SESSION['fb_code'];
        $url .= implode('&', $params);
        $data = explode('&', get_data($url));
        foreach ($data as &$d) {
            $d = explode('=', $d);
            if ($d[0] == 'access_token') {
                $_SESSION['fb_access_token'] = $d[1];
            } elseif ($d[0] == 'expires') {
                $_SESSION['fb_at_expires'] = time() + $d[1];
            }
        }
    }
    if (array_key_exists('fb_access_token', $_SESSION)) {
        if ($_SESSION['fb_at_expires'] > time()) {
            $facebook->setAccessToken($_SESSION['fb_access_token']);
            unset($_SESSION['fb_code']);
        }
    }
}
开发者ID:nodefortytwo,项目名称:engagement,代码行数:30,代码来源:facebook.php

示例7: onNextendFacebook

 function onNextendFacebook(&$facebook)
 {
     $config = new NextendData();
     $config->loadJson(NextendSmartSliderStorage::get(self::$_group));
     require_once dirname(__FILE__) . "/api/facebook.php";
     $facebook = new Facebook(array('appId' => $config->get('apikey', ''), 'secret' => $config->get('apisecret', '')));
     $facebook->setAccessToken($config->get('token', ''));
 }
开发者ID:macconsultinggroup,项目名称:WordPress,代码行数:8,代码来源:facebook.php

示例8: sendToFacebook

 public function sendToFacebook($params)
 {
     // create instance
     $facebook = new Facebook(array('appId' => self::get_facebook_app_id(), 'secret' => self::get_facebook_secret()));
     $facebook->setAccessToken(self::get_facebook_access_token());
     $result = $facebook->api('/' . self::get_facebook_user_id() . '/feed/', 'post', $params);
     return $result;
 }
开发者ID:helpfulrobot,项目名称:pitchandtone-silverstripe-facebookpush,代码行数:8,代码来源:PostToFacebook.php

示例9: render

 /**
  * Render fieldset html
  *
  * @param Varien_Data_Form_Element_Abstract $element
  * @return string
  */
 public function render(Varien_Data_Form_Element_Abstract $element)
 {
     $msg = '<div style="padding-bottom: 1em;max-width: 800px;">';
     $appId = Mage::getStoreConfig('besociable/facebook/appid');
     $appSecret = Mage::getStoreConfig('besociable/facebook/appsecret');
     $currentAccessToken = Mage::getStoreConfig('besociable/facebook/access_token');
     if ($appId != '' && $appSecret != '') {
         $facebook = new Facebook(array('appId' => $appId, 'secret' => $appSecret));
         $merge = $appId . '|' . $appSecret;
         $accessToken = $facebook->getAccessToken();
         if ($accessToken != $merge && $accessToken != $currentAccessToken) {
             Mage::getConfig()->saveConfig('besociable/facebook/access_token', $accessToken);
             $facebook->setAccessToken($accessToken);
         } else {
             $facebook->setAccessToken($currentAccessToken);
         }
         $user = $facebook->getUser();
         if ($user) {
             $loginUrl = $facebook->getLoginUrl(array('scope' => array('manage_pages', 'publish_stream')));
             $msg .= Mage::helper('sociable')->__('<span style="color: green;">You have successfully authorized with facebook.</span>');
             $msg .= Mage::helper('sociable')->__('<br>You can always <a href="%s">click here</a> to re-authorize your access to facebook again.', $loginUrl);
             $msg .= Mage::helper('sociable')->__('<br>If you want to get a list of your pages, you can simply <a href="%s">click here</a>', $this->getUrl('adminhtml/sociable/getPages'));
             $msg .= Mage::helper('sociable')->__('<br>Please <a href="%s">click here</a> to make a test post.', $this->getUrl('adminhtml/sociable/testfacebook'));
             /*
             if(!$user){
             	$loginUrl = $facebook->getLoginUrl(array('scope'=>array('manage_pages','publish_stream')));//, 'publish_actions', 'publish_stream'
             	$msg .= Mage::helper('sociable')->__('<strong style="color:red">Important: </strong>');
             	$msg .= Mage::helper('sociable')->__('You will need to <a href="%s">click here</a> to authorize your access to facebook for the first time.',$loginUrl);
             }else {
             	
             }
             */
         } else {
             $loginUrl = $facebook->getLoginUrl(array('scope' => array('manage_pages', 'publish_stream')));
             //, 'publish_actions', 'publish_stream'
             $msg .= Mage::helper('sociable')->__('<strong style="color:red">Important: </strong>');
             $msg .= Mage::helper('sociable')->__('You will need to <a href="%s">click here</a> to authorize your access to facebook for the first time.', $loginUrl);
         }
     }
     $msg .= '</div>';
     return $msg;
 }
开发者ID:xiaoguizhidao,项目名称:magento,代码行数:48,代码来源:Facebookinfo.php

示例10: fql

 /**
  */
 public static function fql($fql)
 {
     $fb = new Facebook(array('appId' => self::$_app_id, 'secret' => self::$_secret, 'cookie' => true));
     // Radix::dump($fb);
     $uri = sprintf('https://graph.facebook.com/oauth/access_token?client_id=%s&client_secret=%s&grant_type=client_credentials', rawurlencode(self::$_app_id), rawurlencode(self::$_secret));
     $ret = self::_curl($uri);
     if (preg_match('/access_token=(.+)/', $ret['body'], $m)) {
         $fb->setAccessToken($m[1]);
     }
     $ret = $fb->api(array('method' => 'fql.query', 'query' => $fql));
     return $ret;
 }
开发者ID:edoceo,项目名称:radix,代码行数:14,代码来源:facebook.php

示例11: sharePost

 public function sharePost($data = false)
 {
     if (!$data) {
         $data = $this->post;
     }
     $facebook_token = SocialNetwork::get_access_token($data->uid, SocialNetwork::FACEBOOK);
     if ($facebook_token) {
         $facebook = new Facebook(array('appId' => FACEBOOK_APPID, 'secret' => FACEBOOK_SECRET, 'cookie' => true));
         $facebook->setAccessToken($facebook_token->accessToken);
         $facebook->api('/me/feed', 'post', array('message' => $data->title, 'link' => $data->url, 'caption' => $data->content, 'type' => 'link', 'picture' => $data->avatar));
     }
 }
开发者ID:Anpix,项目名称:rede-social,代码行数:12,代码来源:FacebookController.php

示例12: mapFriends

 /**
  * Find friends of logged in user and map to local friends table.
  * @param Array $config
  * @return Bool Success
  */
 public function mapFriends(array $config)
 {
     $config = $config instanceof Garp_Util_Configuration ? $config : new Garp_Util_Configuration($config);
     $config->obligate('bindingModel')->obligate('user_id')->setDefault('accessToken', $this->getAccessToken());
     if (!$config['accessToken']) {
         // Find the auth record
         $authModel = new Model_AuthFacebook();
         $authRow = $authModel->fetchRow($authModel->select()->where('user_id = ?', $config['user_id']));
         if (!$authRow || !$authRow->access_token) {
             return false;
         }
         // Use the stored access token to create a user session. Me() in the FQL ahead will contain the user's Facebook ID.
         // Note that the access token is available for a very limited time. Chances are it's not valid anymore.
         $accessToken = $authRow->access_token;
     }
     try {
         $this->_client->setAccessToken($config['accessToken']);
         // Find the friends' Facebook UIDs
         $friends = $this->_client->api(array('method' => 'fql.query', 'query' => 'SELECT uid2 FROM friend WHERE uid1 = me()'));
         // Find local user records
         $userModel = new Model_User();
         $userTable = $userModel->getName();
         $authFbModel = new Model_AuthFacebook();
         $authFbTable = $authFbModel->getName();
         $fbIds = '';
         $friendCount = count($friends);
         foreach ($friends as $i => $friend) {
             $fbIds .= $userModel->getAdapter()->quote($friend['uid2']);
             if ($i < $friendCount - 1) {
                 $fbIds .= ',';
             }
         }
         $friendQuery = $userModel->select()->setIntegrityCheck(false)->from($userTable, array('id'))->join($authFbTable, $authFbTable . '.user_id = ' . $userTable . '.id', array())->where('facebook_uid IN (' . $fbIds . ')')->order($userTable . '.id');
         $localUsers = $userModel->fetchAll($friendQuery);
         $localUserCount = count($localUsers);
         // Insert new friendships into binding model
         $bindingModel = new $config['bindingModel']();
         $insertSql = 'INSERT IGNORE INTO ' . $bindingModel->getName() . ' (user1_id, user2_id) VALUES ';
         foreach ($localUsers as $i => $localUser) {
             $insertSql .= '(' . $localUser->id . ',' . $config['user_id'] . '),';
             $insertSql .= '(' . $config['user_id'] . ',' . $localUser->id . ')';
             if ($i < $localUserCount - 1) {
                 $insertSql .= ',';
             }
         }
         $result = $bindingModel->getAdapter()->query($insertSql);
         // Clear cache manually, since the table isn't updated thru conventional paths.
         Garp_Cache_Manager::purge($bindingModel);
         return !!$result;
     } catch (Exception $e) {
         return false;
     }
 }
开发者ID:grrr-amsterdam,项目名称:garp3,代码行数:58,代码来源:Facebook.php

示例13: getUserFacebookFriends

 public static function getUserFacebookFriends(GameUsers $user)
 {
     if (!empty($user)) {
         $userId = $user->getUserId();
         $fbId = $user->getFacebookId();
         $oauthTOken = $user->getOauthToken();
         if (!empty($userId) && !empty($fbId) && !empty($oauthTOken)) {
             $facebook = new Facebook(array('appId' => FB_APP_ID, 'secret' => FB_APP_SECRET, 'cookie' => true));
             $facebook->setAccessToken($oauthTOken);
             try {
                 $fbFriends = array();
                 $apiUrl = "/me/friends";
                 while (!empty($apiUrl)) {
                     $result = $facebook->api($apiUrl);
                     $apiUrl = null;
                     if (!empty($result)) {
                         $data = null;
                         if (isset($result["data"])) {
                             $data = $result["data"];
                         }
                         if (!empty($data) && sizeof($data)) {
                             foreach ($data as $fbFriend) {
                                 if (!empty($fbFriend)) {
                                     array_push($fbFriends, $fbFriend);
                                 }
                             }
                         }
                         unset($data);
                         if (isset($result["paging"])) {
                             $paging = $result["paging"];
                             if (!empty($paging) && isset($paging["next"]) && !empty($paging["next"])) {
                                 $next = $paging["next"];
                                 if (strpos($next, "/friends")) {
                                     $apiUrl = "/me" . substr($next, strpos($next, "/friends"));
                                 }
                                 unset($next);
                             }
                             unset($paging);
                         }
                     }
                     unset($result);
                     unset($apiUrl);
                 }
                 return $fbFriends;
             } catch (Exception $exc) {
                 error_log("FriendUtils>getUserFacebookFriends> Error : " . $exc->getMessage() . " Trace : " . $exc->getTraceAsString());
             }
         }
     }
     return null;
 }
开发者ID:bsormagec,项目名称:tavlamania-php,代码行数:51,代码来源:FriendFunctions.php

示例14: _getProfileInfoByAccessToken

 /**
  * get SocialNetwork Profile info from facebook server
  * @param string $accessToken
  */
 public function _getProfileInfoByAccessToken($accessToken = null)
 {
     if ($accessToken) {
         self::$object->setAccessToken($accessToken);
     }
     try {
         self::$oProfile = self::$object->api('/me');
         self::$oProfile = new ArrayObject(self::$oProfile);
         self::$oProfile->setFlags(ArrayObject::ARRAY_AS_PROPS);
         self::$oSocialPlugin = $this;
         return true;
     } catch (Exception $e) {
         SJB_Error::writeToLog($e->getMessage());
     }
     return false;
 }
开发者ID:Maxlander,项目名称:shixi,代码行数:20,代码来源:facebook_social_plugin.php

示例15: confirmIdentityWithCode

 /**
  * Exchanges the code for a valid access token
  *
  * @link https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/#confirm
  *
  * @param \Facebook $facebook
  * @param string $code
  * @param string $redirectUri the redirect uri with which the login url was generated
  *
  * @return bool
  */
 public function confirmIdentityWithCode(\Facebook $facebook, $code, $redirectUri)
 {
     $request = $this->client->get("/oauth/access_token");
     $request->getQuery()->set("client_id", $facebook->getAppId())->set("redirect_uri", $redirectUri)->set("client_secret", $facebook->getAppSecret())->set("code", $code);
     try {
         $response = $request->send();
         parse_str($response->getBody(true), $data);
         if (isset($data["access_token"])) {
             $facebook->setAccessToken($data["access_token"]);
             return true;
         }
         return false;
     } catch (ClientErrorResponseException $e) {
         return false;
     }
 }
开发者ID:ackidri,项目名称:BecklynFacebookBundle,代码行数:27,代码来源:FacebookGraphModel.php


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