本文整理汇总了PHP中Facebook::getLoginUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Facebook::getLoginUrl方法的具体用法?PHP Facebook::getLoginUrl怎么用?PHP Facebook::getLoginUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook
的用法示例。
在下文中一共展示了Facebook::getLoginUrl方法的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: loginBegin
/**
* {@inheritdoc}
*/
function loginBegin()
{
$parameters = array("scope" => $this->scope, "redirect_uri" => $this->endpoint, "display" => "page");
$optionals = array("scope", "redirect_uri", "display", "auth_type");
foreach ($optionals as $parameter) {
if (isset($this->config[$parameter]) && !empty($this->config[$parameter])) {
$parameters[$parameter] = $this->config[$parameter];
//If the auth_type parameter is used, we need to generate a nonce and include it as a parameter
if ($parameter == "auth_type") {
$nonce = md5(uniqid(mt_rand(), true));
$parameters['auth_nonce'] = $nonce;
Hybrid_Auth::storage()->set('fb_auth_nonce', $nonce);
}
}
}
if (isset($this->config['force']) && $this->config['force'] === true) {
$parameters['auth_type'] = 'reauthenticate';
$parameters['auth_nonce'] = md5(uniqid(mt_rand(), true));
Hybrid_Auth::storage()->set('fb_auth_nonce', $parameters['auth_nonce']);
}
// get the login url
$url = $this->api->getLoginUrl($parameters);
// redirect to facebook
Hybrid_Auth::redirect($url);
}
示例3: authenticate
public function authenticate()
{
$session = Yii::app()->session;
$facebook = new Facebook(array('appId' => $this->key, 'secret' => $this->secret));
$here = Yii::app()->request->hostInfo . Yii::app()->request->url;
// Get User ID
$user = $facebook->getUser();
// already logged in
if (isset($user)) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
$session['facebook_user'] = $user_profile;
$this->_authenticated = true;
} catch (FacebookApiException $e) {
$user = null;
$params = array("scope" => "user_birthday,email,read_stream");
$loginUrl = $facebook->getLoginUrl($params);
Yii::app()->request->redirect($loginUrl);
}
// Log in!
} else {
$params = array("scope" => "user_birthday,email,read_stream");
$loginUrl = $facebook->getLoginUrl($params);
Yii::app()->request->redirect($loginUrl);
}
return $this->_authenticated;
}
示例4: 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'));
}
}
示例5: 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');
}
}
示例6: 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>";
}
}
示例7: call
public function call()
{
//echo $this->_fbLoginRedirectUrl;exit;
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array('appId' => $this->_fbAppId, 'secret' => $this->_fbAppSecret, 'cookie' => false));
// Get User ID
$this->_fbUser = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($this->_fbUser) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$this->_fbUserProfile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$this->_fbUser = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($this->_fbUser) {
$this->_fbLogoutUrl = $facebook->getLogoutUrl(array("next" => $this->_fbLogoutRedirectUrl));
} else {
$this->_fbLoginUrl = $facebook->getLoginUrl(array('redirect_uri' => $this->_fbLoginRedirectUrl));
//echo $this->_fbLoginUrl;exit;
}
}
示例8: index
function index()
{
$this->load->config('facebook');
$this->load->library('form_validation');
$this->form_validation->set_rules('fullname', 'Full Name', 'required|xss_clean');
$this->form_validation->set_rules('email', 'Email Address', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
$this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required');
include_once APPPATH . 'third_party/facebook.php';
$facebook = new Facebook(array('appId' => $this->config->item('facebook_app_id'), 'secret' => $this->config->item('facebook_api_secret'), 'cookie' => true));
$param = array('next' => site_url('/member/registration/fb'));
$this->tpl['fb_login_url'] = $facebook->getLoginUrl($param);
if ($this->form_validation->run() == true) {
$username = strtolower($this->input->post('fullname'));
$email = $this->input->post('email');
$password = $this->input->post('password');
$additional_data = array('fullname' => $this->input->post('fullname'));
}
if ($this->form_validation->run() == true && $this->ion_auth->register($username, $password, $email, $additional_data)) {
$this->session->set_flashdata('message', "User Created");
die('redirect to sumthin lah');
} else {
$this->tpl['message'] = validation_errors() ? validation_errors() : $this->ion_auth->errors();
$this->tpl['content'] = $this->load->view('registration_index', $this->tpl, true);
$this->load->view('member/body', $this->tpl);
}
}
示例9: 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;
}
示例10: requestToken
public function requestToken($Account)
{
$NGPushIni = eZINI::instance('ngpush.ini');
$SiteIni = eZINI::instance('site.ini');
$AccessToken = $NGPushIni->variable($Account, 'AccessToken');
// If access tokens are given
if ($AccessToken) {
//Save request signing tokens to cache
ngPushBase::save_token($Account, $AccessToken, 'main_token');
} else {
$AdministrationUrl = '/';
eZURI::transformURI($AdministrationUrl, false, 'full');
$AdministrationUrl = base64_encode($AdministrationUrl);
$SettingsBlock = base64_encode($Account);
$redirectUrl = 'http://' . $NGPushIni->variable('PushNodeSettings', 'ConnectURL') . '/redirect.php/' . $AdministrationUrl . '/' . $SettingsBlock . '?case=facebook';
$Facebook = new Facebook(array('appId' => $NGPushIni->variable($Account, 'AppAPIKey'), 'secret' => $NGPushIni->variable($Account, 'AppSecret')));
$Permissions = array('publish_actions', 'user_posts');
if ($NGPushIni->variable($Account, 'EntityType') == 'page') {
$Permissions[] = 'manage_pages';
}
$state = md5(uniqid(rand(), true));
$http = eZHTTPTool::instance();
$http->setSessionVariable('ngpush_state', $state);
$LoginUrl = $Facebook->getLoginUrl(array('redirect_uri' => $redirectUrl, 'scope' => implode($Permissions, ','), 'state' => $state));
self::$response['RequestPermissionsUrl'] = $LoginUrl;
}
}
示例11: authorizefacebookAction
public function authorizefacebookAction()
{
$appId = Mage::getStoreConfig('besociable/facebook/appid');
$appSecret = Mage::getStoreConfig('besociable/facebook/appsecret');
$pageId = Mage::getStoreConfig('besociable/facebook/pageid');
if ($appId != '' && $appSecret != '') {
$facebook = new Facebook(array('appId' => $appId, 'secret' => $appSecret));
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me', 'GET', array('ref' => 'fbwpp'));
} catch (FacebookApiException $e) {
Mage::getSingleton("adminhtml/session")->addError(Mage::helper("sociable")->__("Cannot login! Please double check your data!"));
$user = null;
}
} else {
Mage::getSingleton("adminhtml/session")->addError(Mage::helper("sociable")->__("Please enter your facebook app info!"));
}
if ($user) {
Mage::getSingleton("adminhtml/session")->addSuccess(Mage::helper("sociable")->__("You have successfully authorized with facebook."));
$this->_redirect("*/system_config/edit/section/besociable/");
} else {
try {
$loginUrl = $facebook->getLoginUrl(array('scrope' => array('manage_pages', 'publish_actions', 'publish_stream')));
$this->_redirect($loginUrl);
} catch (Exception $ex) {
Mage::getSingleton("adminhtml/session")->addError(Mage::helper("sociable")->__("Cannot login! Please double check your data!"));
}
}
} else {
Mage::getSingleton("adminhtml/session")->addError(Mage::helper("sociable")->__("Please enter your facebook app info!"));
}
$this->_redirect("*/system_config/edit/section/besociable/");
}
示例12: authenticate
public function authenticate(CakeRequest $request, CakeResponse $response)
{
$user = $this->_Collection->Auth->user();
$service = strtolower($request->params['pass'][0]);
if ($service !== $this->service) {
return false;
}
try {
$facebook = new Facebook(array('appId' => $this->myConsumerKey, 'secret' => $this->myConsumerSec, 'cookie' => true));
$action = $request->params['action'];
if ($action === 'login') {
$url = $facebook->getLoginUrl(array('redirect_uri' => Router::url('callback/facebook/', true), 'scope' => 'email,publish_stream'));
if ($url !== null) {
$response->header('Location', $url);
$response->send();
}
} elseif ($action === 'callback') {
preg_match('/state=(.*)/', $_REQUEST['url'], $state);
$_REQUEST['state'] = $state[1];
$accessToken = $facebook->getAccessToken();
if ($accessToken != '') {
$this->_fetch($facebook, $accessToken, $response);
} else {
//you should throw exception
}
}
} catch (OAuthException $E) {
//you can catch OAuth exception
}
}
示例13: openAction
/**
* Renders the bookmarklet when it is opened. Gets the URL of the item being ingested through the Request container,
* sends it to the parser and renders the result on the bookmarklet if it can be ingested or an error otherwise.
*
* @return Response
*
*/
public function openAction()
{
$request = $this->getRequest();
$session = $request->getSession();
// get logged user
$user = $this->get('security.context')->getToken()->getUser();
$widgetId = $request->query->get('widget-id');
$itemUrl = $request->query->get('url');
$parserResponse = $this->forward('ZeegaApiBundle:Items:getItemsParser', array(), array("url" => $itemUrl))->getContent();
$parserResponse = json_decode($parserResponse, true);
$message = "SORRY! We can't add this item.";
if (isset($parserResponse)) {
//var_dump($parserResponse);
$isUrlValid = $parserResponse["request"]["parser"]["success"];
$isUrlCollection = $parserResponse["request"]["parser"]["is_set"];
$message = $parserResponse["request"]["parser"]["message"];
$items = $parserResponse["items"];
if ($isUrlValid && count($items) > 0) {
$parsedItem = $items[0];
// check if the item exists on the database
$item = $this->getDoctrine()->getRepository('ZeegaDataBundle:Item')->findOneBy(array("user" => $user->getId(), "attributionUri" => $parsedItem["attribution_uri"], "enabled" => 1));
if (isset($item)) {
$update = 1;
$parsedItem["id"] = $item->getId();
} else {
$update = 0;
}
if ($parsedItem["archive"] == "Dropbox") {
if (!$update && $parsedItem["child_items_count"] == 0) {
// Dropbox - welcome screen for the initial connection with dropbox
return $this->render('ZeegaBookmarkletBundle:Bookmarklet:dropboxwelcome.widget.html.twig', array('displayname' => $user->getDisplayname(), 'widget_id' => $widgetId, 'item' => json_encode($parsedItem), 'update' => $update, 'child_items_count' => $parsedItem["child_items_count"], 'archive' => $parsedItem["archive"]));
}
} else {
if ($parsedItem["archive"] == "Facebook") {
// Facebook - needs to be loaded in a pop-up
if ($parsedItem["child_items_count"] == -1) {
// no access token. overloading child_items_count is a hack. Find cleaner way soon.
//header('X-Frame-Options: Allow');
$requirePath = __DIR__ . '/../../../../vendor/facebook/facebook.php';
require_once $requirePath;
$facebook = new \Facebook(array('appId' => '459848834048078', 'secret' => 'f5b344b91bff03ace4df454e35fca4e4'));
$loginUrlParams = array('scope' => 'user_photos,friends_photos', 'display' => 'popup');
$loginUrl = $facebook->getLoginUrl($loginUrlParams);
return $this->render('ZeegaBookmarkletBundle:Bookmarklet:facebookWelcome.widget.html.twig', array('displayname' => $user->getDisplayname(), 'widget_id' => $widgetId, 'item' => json_encode($parsedItem), 'update' => $update, 'archive' => $parsedItem["archive"], 'child_items_count' => $parsedItem["child_items_count"], 'login_url' => $loginUrl));
} else {
// access token
return $this->render('ZeegaBookmarkletBundle:Bookmarklet:widget.html.twig', array('displayname' => $user->getDisplayname(), 'widget_id' => $widgetId, 'item' => json_encode($parsedItem), 'update' => $update, 'archive' => $parsedItem["archive"], 'thumbnail_url' => $parsedItem["thumbnail_url"], 'child_items_count' => $parsedItem["child_items_count"]));
}
} else {
if ($update) {
return $this->render('ZeegaBookmarkletBundle:Bookmarklet:duplicate.widget.html.twig', array('displayname' => $user->getDisplayname(), 'widget_id' => $widgetId, 'item' => $item, 'update' => $update, 'archive' => $parsedItem["archive"]));
}
}
}
// for all other cases
return $this->render('ZeegaBookmarkletBundle:Bookmarklet:widget.html.twig', array('displayname' => $user->getDisplayname(), 'widget_id' => $widgetId, 'item' => json_encode($parsedItem), 'update' => $update, 'archive' => $parsedItem["archive"], 'thumbnail_url' => $parsedItem["thumbnail_url"], 'child_items_count' => $parsedItem["child_items_count"]));
}
}
return $this->render('ZeegaBookmarkletBundle:Bookmarklet:fail.widget.html.twig', array('displayname' => $user->getDisplayname(), 'widget_id' => $widgetId, 'item' => json_encode(array()), 'urlmessage' => $message, 'url' => $itemUrl, 'archive' => ""));
}
示例14: get_user_data_fb
public function get_user_data_fb()
{
parse_str($_SERVER['QUERY_STRING'], $_REQUEST);
$facebook = new Facebook(array('appId' => '876274572459160', 'secret' => 'c44768470ff9f9d7a52784f6f5fbfd9a', 'cookie' => true, 'redirect_uri' => 'kepoabis.com'));
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2;
$user = $facebook->getUser();
$user_data = array();
if ($user) {
try {
$user_data = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
$url = "";
$img = "";
if ($user) {
$url = "<strong><em>You are connected with Facebook.<br></em></strong>";
//$facebook->getLogoutUrl();
$img = "https://graph.facebook.com/" . $user . "/picture";
} else {
$url = "<a class='btn btn-default btn-social btn-facebook' href=" . $facebook->getLoginUrl() . "><i class='fa fa-facebook'></i>Sign in with Facebook</a>";
}
return array("url" => $url, "img" => $img, "is_login" => $user, "user_data" => $user_data);
}
示例15: getFacebookLoginUrl
public static function getFacebookLoginUrl()
{
if (is_object(self::$object)) {
return self::$object->getLoginUrl(array('scope' => implode(',', self::$aPermissionFields)));
}
return false;
}