我正在尝试在我的网站上实施facebook登录,但我被困在这里。 我需要用户的电子邮件。 我要求权限。如果权限授予一切都很好。 如果按下“Not Now”按钮(权限被拒绝)并且他尝试再次登录该站点,则将不再显示权限弹出窗口。 如何为不接受权限的用户再次显示“弹出窗口”?谢谢!
<?php
if(!isset($_SESSION))
{
session_start();
}
?>
<?php
require_once '/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// start session
// init app with app id and secret
FacebookSession::setDefaultApplication( '12345','12345' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('urlcallback' );
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
} catch( Exception $ex ) {
// When validation fails or other local issues
}
// see if we have a session
if ( isset( $session ) ) {
// graph api request for user data
$request = new FacebookRequest( $session, 'GET', '/me?fields=name,email' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fbid = $graphObject->getProperty('id'); // To Get Facebook ID
$fbuname = $graphObject->getProperty('username'); // To Get Facebook Username
$fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
$femail = $graphObject->getProperty('email'); // To Get Facebook email ID
/* ---- Session Variables -----*/
$_SESSION['FBID'] = $fbid;
$_SESSION['USERNAME'] = $fbuname;
$_SESSION['FULLNAME'] = $fbfullname;
$_SESSION['EMAIL'] = $femail;
echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>';
//echo 'email:'.$femail;
} else {
// show login url
echo '<a href="' . $helper->getLoginUrl(array('scope'=>'public_profile,email,user_friends')) . '">Login</a>';
}
?>
答案 0 :(得分:0)
解决方案添加公共函数getLoginUrl:
service: aws-nodejs # NOTE: update this with your service name
provider:
name: aws
runtime: nodejs6.10
functions:
hello:
handler: handler.deletecustomer
events:
- http:
path: /deletecustomer
method: post
cors: true
resources:
Resources:
tablenotes:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: noteId
AttributeType: S
- AttributeName: userId
AttributeType: S
KeySchema:
- AttributeName: userId
KeyType: HASH
- AttributeName: noteId
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: '5'
WriteCapacityUnits: '5'
mysamplebucket:
Type: AWS::S3::Bucket
Properties:
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: error.html
AccessControl: Private
VersioningConfiguration:
Status: Suspended