本文整理汇总了PHP中Facebook\FacebookRequest类的典型用法代码示例。如果您正苦于以下问题:PHP FacebookRequest类的具体用法?PHP FacebookRequest怎么用?PHP FacebookRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FacebookRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
// Same time next week! :D
$job = (new \App\Jobs\WeeklyMail())->delay(604800);
$this->dispatch($job);
// We'll just want to double-check our Facebook events still exist
// before we email people about them...
FacebookSession::setDefaultApplication(getenv('FB_ID'), getenv('FB_SECRET'));
$session = FacebookSession::newAppSession();
try {
$session->validate();
} catch (FacebookRequestException $ex) {
// Session not valid, Graph API returned an exception with the reason.
dd($ex);
} catch (\Exception $ex) {
// Graph API returned info, but it may mismatch the current app or have expired.
dd($ex);
}
$all_events = Event::where('time', '>', date('Y-m-d H:i:s'))->where('time', '<', date('Y-m-d H:i:s', time() + 604800))->get();
foreach ($all_events as $event) {
$request = new FacebookRequest($session, 'GET', "/" . $event->facebook_id);
try {
$response = $request->execute();
} catch (\Exception $ex) {
// Facebook Exception looking up event; probably deleted, should mirror here.
$event->delete();
}
}
foreach (User::where('unsubscribed_email', 'no') as $user) {
$this->dispatch(new SendEmail($user));
}
}
开发者ID:boregan,项目名称:lowdown,代码行数:37,代码来源:WeeklyMail.php
示例2: findPosts
public function findPosts()
{
$settings = craft()->plugins->getPlugin('social')->getSettings();
$user_id = $settings->facebook_user_id;
$session = $this->getFacebookSession();
if ($session === false) {
return array();
}
$request = new FacebookRequest($session, 'GET', "/{$user_id}/posts");
$response = $request->execute();
$graph_objects = $response->getGraphObjectList();
$posts = array();
$f = 'http://www.facebook.com/';
foreach ($graph_objects as $graph_object) {
$native = $graph_object->asArray();
// remove the 'trailing' t.co link
if (isset($native['message'])) {
$message = preg_replace('#http://t.co/[^ ]*$#', '', $native['message']);
} else {
$message = null;
}
// linkify remaining URLs
$message = preg_replace('/(https?:\\/\\/([A-Za-z0-9-._~:\\/?#\\[\\]@!$&\'()*+,;=%]*))/', '<a href="\\1">\\2</a>', $message);
$posts[] = array('network' => 'Facebook', 'message' => $message, 'link' => isset($native['link']) ? $native['link'] : $f . $native['id'], 'picture' => isset($native['picture']) ? $native['picture'] : false, 'author' => $native['from']->name, 'author_link' => $f . $native['from']->id, 'created' => strtotime($native['created_time']), 'print_r' => print_r($native, true), 'native' => $native);
}
return $posts;
}
开发者ID:imarc,项目名称:craft-social,代码行数:27,代码来源:Social_FacebookService.php
示例3: action_index
public function action_index()
{
$gameList = DB::query(Database::SELECT, "SELECT * FROM game")->execute();
$this->template->content = $gameList[0]['name'];
require_once Kohana::find_file('vendor', 'vendor/autoload');
$config = Kohana::$config->load('auth');
//$session = Session::instance($config['session_type']);
FacebookSession::setDefaultApplication('376812619137510', 'd054fff7f6146da72c9585d78d0357b5');
$helper = new FacebookJavaScriptLoginHelper();
try {
$session = $helper->getSession();
} catch (FacebookRequestException $ex) {
// When Facebook returns an error
$this->template->content = "fb returned an error";
} catch (\Exception $ex) {
// When validation fails or other local issues
$this->template->content = "validation failed";
//print_r($ex);
}
if (isset($session)) {
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
$graphObject = $response->getGraphObject();
if (isset($graphObject->id)) {
$loginData = array('first_name' => $graphObject->first_name);
}
$this->template->content = "Hi, " . $graphObject->getProperty('first_name');
} else {
echo "No session";
}
}
开发者ID:Xackery,项目名称:coop,代码行数:31,代码来源:Facebook.php
示例4: makePPonFb
public function makePPonFb($photo)
{
$request = new FacebookRequest($this->global, 'GET', '/me/albums');
$album_id = '';
$response = $request->execute();
$graphObject = $response->getGraphObject()->asArray();
$arr = $graphObject['data'];
foreach ($arr as $pr) {
$ar = get_object_vars($pr);
if ($ar['name'] == 'Profile Pictures') {
if ($ar['can_upload'] == 1) {
$album_id = $ar['id'];
} else {
$album_id = 0;
}
}
}
/* handle the result */
if ($album_id != 0) {
$request = new FacebookRequest($this->global, 'POST', '/' . $album_id . '/photos', array('source' => '@' . $photo));
$response = $request->execute();
$graph = $response->getGraphObject()->asArray();
echo 'https://www.facebook.com/photo.php?fbid=' . $graph['id'] . '&makeprofile=1';
} else {
echo '0';
}
}
开发者ID:samundrak,项目名称:fadkit,代码行数:27,代码来源:__aaa__.php
示例5: getUserDataFromFb
function getUserDataFromFb($session)
{
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
$graphObject = $response->getGraphObject()->asArray();
return $graphObject;
}
开发者ID:thunderclap560,项目名称:quizkpop,代码行数:7,代码来源:UserController.php
示例6: RevokeAccess
/**
* Function to revoke the application access to Facebook account.
* @param array ['access_token'=> authorized user access token, 'user_id'=> user id, 'media_id'=> facebook media id, 'permissions'=> user permission to revoke]
* @return boolean true|false
* @throws FacebookSDKException if ((user id OR media id) AND access token) OR permission to revoke are missing
*
*/
public function RevokeAccess($params)
{
$USER_ID = isset($params[self::USER_ID]) ? $params[self::USER_ID] : null;
$FACEBOOK_MEDIA_ID = isset($params[self::MEDIA_ID]) ? $params[self::MEDIA_ID] : null;
$ACCESS_TOKEN = isset($params[self::AUTH_TOKEN]) ? $params[self::AUTH_TOKEN] : null;
$USER_ID = isset($params[self::USER_ID]) ? $params[self::USER_ID] : null;
$PERMISSION_TO_REVOKE = isset($params[self::PERMISSIONS]) ? $params[self::PERMISSIONS] : null;
// 0. Check if permission is set
// if(empty($PERMISSION_TO_REVOKE))
// throw new FacebookSDKException('Revoke permission is not set.');
// 1. If IS NOT set access token - get from DB by USER_ID
if (empty($ACCESS_TOKEN)) {
if (empty($USER_ID)) {
throw new FacebookSDKException('To get access token from DB you need to supply USER_ID');
}
if (empty($FACEBOOK_MEDIA_ID)) {
throw new FacebookSDKException('To get access token from DB you need to supply FACEBOOK_MEDIA_ID');
}
$params_social = array(\Av\MediaUserModel::MEDIA_ID => $FACEBOOK_MEDIA_ID, \Av\MediaUserModel::USER_ID => $USER_ID);
$oSocialUserMapper = new \Av\MediaUserModel();
$access_token_info = $oSocialUserMapper->GetCredentials($params_social);
$ACCESS_TOKEN = isset($access_token_info[\Av\MediaUserModel::ACCESS_TOKEN]) ? $access_token_info[\Av\MediaUserModel::ACCESS_TOKEN] : null;
if (empty($ACCESS_TOKEN)) {
throw new FacebookSDKException("No access token is saved for USER_ID {$USER_ID}");
}
}
$session = new FacebookSession($ACCESS_TOKEN);
$request = new FacebookRequest($session, 'DELETE', "/me/permissions/{$PERMISSION_TO_REVOKE}");
$graphObject = $request->execute()->getGraphObject();
$this->AddDebug(__METHOD__ . " #" . __LINE__ . "permission {$PERMISSION_TO_REVOKE} deleted with status " . print_r($graphObject, true));
}
开发者ID:avassilenko,项目名称:av_2,代码行数:38,代码来源:FacebookDeauthorizeController.php
示例7: connect
/**
* @param $redirect_url
* @return string|Facebook\GraphUser Login URL or GraphUser
*/
function connect($redirect_url)
{
FacebookSession::setDefaultApplication($this->appId, $this->appSecret);
$helper = new FacebookRedirectLoginHelper($redirect_url);
if (isset($_SESSION) && isset($_SESSION['fb_token'])) {
$session = new FacebookSession($_SESSION['fb_token']);
} else {
$session = $helper->getSessionFromRedirect();
}
if ($session) {
try {
$_SESSION['fb_token'] = $session->getToken();
$request = new FacebookRequest($session, 'GET', '/me');
$profile = $request->execute()->getGraphObject('Facebook\\GraphUser');
if ($profile->getEmail() === null) {
throw new \Exception('L\'email n\'est pas disponible');
}
return $profile;
} catch (\Exception $e) {
unset($_SESSION['fb_token']);
return $helper->getReRequestUrl(['email']);
}
} else {
return $helper->getLoginUrl(['email']);
}
}
开发者ID:rizof,项目名称:Laravel-conexion,代码行数:30,代码来源:ConnexionFacebook.php
示例8: grabPhotos
public function grabPhotos($albumId)
{
$request = new FacebookRequest($this->session, 'GET', '/' . $albumId . '/photos');
$response = $request->execute();
$graphObject = $response->getGraphObject();
$data = $graphObject->getProperty('data');
return $data;
}
开发者ID:predever,项目名称:AppMaker,代码行数:8,代码来源:FacebookContentGrabber.php
示例9: fromFb
private function fromFb($action, $method = 'GET')
{
$accessToken = \Yii::$app->request->post('accessToken');
$session = new FacebookSession($accessToken);
$request = new FacebookRequest($session, $method, $action);
$response = $request->execute();
return $response->getGraphObject()->asArray();
}
开发者ID:griga,项目名称:m22-cms,代码行数:8,代码来源:ApiController.php
示例10: getUserInfo
private function getUserInfo()
{
FacebookSession::setDefaultApplication(Config::get('facebook.appid'), Config::get('facebook.secret'));
$helper = new FacebookRedirectLoginHelper('http://localhost:8000/home');
$userID = "";
$userEmail = "";
$userName = "";
$userPicUrl = "";
try {
$session = $helper->getSessionFromRedirect();
} catch (FacebookRequestException $ex) {
// When Facebook returns an error
} catch (\Exception $ex) {
// When validation fails or other local issues
}
if (isset($_SESSION['token'])) {
// We have a token, is it valid?
$session = new FacebookSession($_SESSION['token']);
try {
$session->Validate(Config::get('facebook.appid'), Config::get('facebook.secret'));
} catch (FacebookAuthorizationException $ex) {
// Session is not valid any more, get a new one.
$session = '';
}
}
if (isset($session)) {
$_SESSION['token'] = $session->getToken();
$request = new FacebookRequest($session, 'GET', '/me?fields=id,name,email,picture');
$response = $request->execute();
$graphObject = $response->getGraphObject();
$userID = $graphObject->getProperty('id');
$userName = $graphObject->getProperty('name');
$userEmail = $graphObject->getProperty('email');
$userPicObj = $graphObject->getProperty('picture')->asArray();
$userPicUrl = $userPicObj['url'];
$_SESSION['usrID'] = $userID;
$_SESSION['usrName'] = $userName;
$_SESSION['usrEmail'] = $userEmail;
$_SESSION['usrPicUrl'] = $userPicUrl;
$user_model = App\user::where('user_id', $userID)->first();
if (is_null($user_model)) {
$user_model = new App\user();
$user_model->user_id = $userID;
$user_model->user_name = $userName;
$user_model->user_email = $userEmail;
$user_model->user_profilePic = $userPicUrl;
$user_model->save();
} else {
$user_model->user_name = $userName;
$user_model->user_email = $userEmail;
$user_model->user_profilePic = $userPicUrl;
$user_model->save();
}
}
$data = array("user_id" => $userID, "user_name" => $userName, "user_email" => $userEmail, "user_profilePic" => $userPicUrl);
$data = array("user_id" => $userID, "user_name" => $userName, "user_email" => $userEmail, "user_profilePic" => $userPicUrl);
return $data;
}
开发者ID:CoffeeOwl17,项目名称:HEXA,代码行数:58,代码来源:HomeController.php
示例11: getUserPicture
/**
* Retourne l'image principale de l'utilisateur
* @param FacebookSession $session [description]
* @param AdvancedUserInterface $user [description]
* @return [type] [description]
*/
public function getUserPicture(FacebookSession $session, AdvancedUserInterface $user)
{
if (!is_null($user->getFacebookId())) {
$request = new FacebookRequest($session, 'GET', '/me/picture', ['redirect' => false, 'type' => 'large']);
$response = $request->execute();
$graphObject = $response->getGraphObject();
return $graphObject->getProperty('url');
}
}
开发者ID:studiocaramia,项目名称:redking_OAuthBundle,代码行数:15,代码来源:Facebook.php
示例12: testAppSecretProof
public function testAppSecretProof()
{
FacebookSession::enableAppSecretProof(true);
$request = new FacebookRequest(FacebookTestHelper::$testSession, 'GET', '/me');
$this->assertTrue(isset($request->getParameters()['appsecret_proof']));
FacebookSession::enableAppSecretProof(false);
$request = new FacebookRequest(FacebookTestHelper::$testSession, 'GET', '/me');
$this->assertTrue(!isset($request->getParameters()['appsecret_proof']));
}
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:9,代码来源:FacebookRequestTest.php
示例13: _getChannelV4
private static function _getChannelV4($channel)
{
FacebookSession::setDefaultApplication(self::FACEBOOK_APP_ID, self::FACEBOOK_SECRET_KEY);
$session = FacebookSession::newAppSession(self::FACEBOOK_APP_ID, self::FACEBOOK_SECRET_KEY);
$request = new FacebookRequest($session, 'GET', '/' . $channel . '/posts?fields=type,created_time,message,picture,object_id,link');
$response = $request->execute();
$graphObject = $response->getGraphObject();
return $graphObject->getPropertyAsArray('data');
}
开发者ID:erichub,项目名称:Presence-V-0.1,代码行数:9,代码来源:Facebook.class.php
示例14: deleteTestUser
public static function deleteTestUser()
{
if (!static::$testUserId) {
return;
}
$testUserPath = '/' . static::$testUserId;
$request = new FacebookRequest(static::getAppSession(), 'DELETE', $testUserPath);
$request->execute();
}
开发者ID:sodacrackers,项目名称:washyacht,代码行数:9,代码来源:FacebookTestHelper.php
示例15: facebook
public function facebook()
{
$facebook_default_scope = explode(',', $this->ci->config->item("facebook_default_scope"));
$facebook_app_id = $this->ci->config->item("facebook_app_id");
$facebook_api_secret = $this->ci->config->item("facebook_api_secret");
// init app with app id and secret
FacebookSession::setDefaultApplication($facebook_app_id, $facebook_api_secret);
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper(site_url('login/facebook'));
// see if a existing session exists
if (isset($_SESSION) && isset($_SESSION['fb_token'])) {
// create new session from saved access_token
$session = new FacebookSession($_SESSION['fb_token']);
// validate the access_token to make sure it's still valid
try {
if (!$session->validate()) {
$session = null;
}
} catch (Exception $e) {
// catch any exceptions
$session = null;
}
}
if (!isset($session) || $session === null) {
// no session exists
try {
$session = $helper->getSessionFromRedirect();
} catch (FacebookRequestException $ex) {
// When Facebook returns an error
// handle this better in production code
print_r($ex);
} catch (Exception $ex) {
// When validation fails or other local issues
// handle this better in production code
print_r($ex);
}
}
// see if we have a session
if (isset($session)) {
// save the session
$_SESSION['fb_token'] = $session->getToken();
// create a session using saved token or the new one we generated at login
$session = new FacebookSession($session->getToken());
// graph api request for user data
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject()->asArray();
$fb_data = array('me' => $graphObject, 'loginUrl' => $helper->getLoginUrl($facebook_default_scope));
$this->ci->session->set_userdata('fb_data', $fb_data);
} else {
$fb_data = array('me' => null, 'loginUrl' => $helper->getLoginUrl($facebook_default_scope));
$this->ci->session->set_userdata('fb_data', $fb_data);
}
return $fb_data;
}
开发者ID:chenbingchn,项目名称:codeigniter-facebook-php-sdk-v4,代码行数:56,代码来源:lib_login.php
示例16: example
public function example()
{
$application = FacebookSession::setDefaultApplication($this->config['app_id'], $this->config['app_secret']);
$session = FacebookSession::newAppSession();
$request = new FacebookRequest($session, 'GET', '/780788985274738');
$response = $request->execute();
$graphObject = $response->getGraphObject();
$response = $this->app->json($graphObject->asArray(), 200);
return $response;
}
开发者ID:andyjessop,项目名称:bolt-facebook-starter,代码行数:10,代码来源:Extension.php
示例17: login
public function login($data = null)
{
if (isset($_SESSION['facebook'])) {
$session = new FacebookSession($_SESSION['facebook']);
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
$graphObject = $response->getGraphObject()->asArray();
require render_template . "Splash/index.php";
}
}
开发者ID:ricardo-pcan,项目名称:eixfie_social,代码行数:10,代码来源:TematicLinesController.php
示例18: getRSS
/**
* Crée un RSS a partir du flux (fb ou non) et le store
* @param $feed : feed got from the database
* @return string
* @throws \Facebook\FacebookRequestException
*/
public function getRSS($feed)
{
//get directly the rss in the storage if exists
if (Storage::exists($this->rssDirectory . 'feed_' . $feed->id . '.xml')) {
return Storage::get($this->rssDirectory . 'feed_' . $feed->id . '.xml');
}
//if it's a facebook page : convert to rss
if ($feed->is_facebook) {
$url = parse_url($feed->url);
$page = $url['path'];
$application = array('app_id' => getenv('FACEBOOK_APP_ID'), 'app_secret' => getenv('FACEBOOK_APP_SECRET'));
FacebookSession::setDefaultApplication($application['app_id'], $application['app_secret']);
$session = new FacebookSession($application['app_id'] . '|' . $application['app_secret']);
$request = new FacebookRequest($session, 'GET', '/' . $page . '/feed');
$response = $request->execute();
$graphObject = $response->getGraphObject();
$facebook_feed = $graphObject->asArray();
$xml = '
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>RSS ' . $feed->name . '</title>
<description></description>
';
foreach ($facebook_feed['data'] as $entry) {
//récupere l'id de la page et l'id du post
$ids = explode('_', $entry->id);
if ($entry->from->id == $ids[0] && isset($entry->message)) {
//si il y a un message et que la page est auteur
$title = Str::words($entry->message, 20, '...');
//limit mots
$pubDate = date("D, d M Y H:i:s T", strtotime($entry->created_time));
$item = '
<item>
<title><![CDATA[' . $title . ']]></title>
<link>http://www.facebook.com/' . $ids[0] . '/posts/' . $ids[1] . '</link>
<pubDate>' . date("r", strtotime($pubDate)) . '</pubDate>
</item>';
$xml .= $item;
}
}
$xml .= '</channel></rss>';
} else {
$context = stream_context_create(array('http' => array('user_agent' => 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11')));
$xml = @file_get_contents($feed->url, FALSE, $context);
}
$xml = trim($xml);
// if the file is not xml return false
$xml_is_valid = @simplexml_load_string($xml);
if (!$xml_is_valid) {
throw new \Exception('invalid xml');
}
Storage::put($this->rssDirectory . 'feed_' . $feed->id . '.xml', $xml);
return $xml;
}
开发者ID:gabva,项目名称:feeds,代码行数:61,代码来源:EloquentFeedRepository.php
示例19: getData
public function getData()
{
if (isset($_SESSION['fbData'])) {
return unserialize($_SESSION['fbData']);
} else {
$request = new FacebookRequest($this->session, 'GET', '/me');
$profile = $request->execute()->getGraphObject('\\zoneroot\\fbconnect\\fbdata');
$_SESSION['fbData'] = serialize($profile);
return $profile;
}
}
开发者ID:zoneroot,项目名称:fbconnect,代码行数:11,代码来源:fbconnect.php
示例20: createUserProfile
private function createUserProfile(FacebookSession $session, GraphUser $user)
{
$profile = new UserProfile();
$profilePicReq = new FacebookRequest($session, 'GET', '/me/picture', ['redirect' => 0, 'type' => 'large']);
$pic = $profilePicReq->execute()->getGraphObject()->asArray();
$profile['displayName'] = $user->getName();
$profile['profileUrl'] = $user->getLink();
$profile['imageUrl'] = $pic['url'];
//TODO other props
return $profile;
}
开发者ID:kapitchi,项目名称:kap-security,代码行数:11,代码来源:FacebookJavascript.php
注:本文中的Facebook\FacebookRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论