本文整理汇总了PHP中Facebook\FacebookRequest类的典型用法代码示例。如果您正苦于以下问题:PHP FacebookRequest类的具体用法?PHP FacebookRequest怎么用?PHP FacebookRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FacebookRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
}
示例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;
}
示例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";
}
}
示例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';
}
}
示例5: getUserDataFromFb
function getUserDataFromFb($session)
{
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
$graphObject = $response->getGraphObject()->asArray();
return $graphObject;
}
示例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));
}
示例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']);
}
}
示例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;
}
示例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();
}
示例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;
}
示例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');
}
}
示例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']));
}
示例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');
}
示例14: deleteTestUser
public static function deleteTestUser()
{
if (!static::$testUserId) {
return;
}
$testUserPath = '/' . static::$testUserId;
$request = new FacebookRequest(static::getAppSession(), 'DELETE', $testUserPath);
$request->execute();
}
示例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;
}