js-SDK から取得したアクセス トークンを ajax リクエストと共に PHP に渡し、それを PHP で使用することもできます。
<script>
// This is called with the results from from FB.getLoginStatus().
function statusChangeCallback(response) {
console.log(response);
if (response.status === 'connected') {
// Logged into your app and Facebook.
// testAPI();
var accessToken = response.authResponse.accessToken;
console.log(accessToken);
//ajax call to PHP **************************************************************
//*******************************************************************************
$.get("/ajaxpage.php?token="+accessToken+"&uid="+response.authResponse.userID,"",function(data){
// on reply from the server
});
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
} else {
// The person is not logged into Facebook.
}
}
// This function is called when someone finishes with the Login
// Button. See the onlogin handler attached to it in the sample
// code below.
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId: '..................',
cookie: true, // enable cookies to allow the server to access the session
xfbml: true, // parse social plugins on this page
version: 'v2.2' // use version 2.2
});
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>