Viewing file: index.php (4.05 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<!DOCTYPE html>
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">
</head>
<body>
<script>
function statusChangeCallback(response) { // Called with the results from FB.getLoginStatus().
// FB.logout(function(response) {
// // user is now logged out
// console.log(response);
// });
if (response.status === 'connected') { // Logged into your webpage and Facebook.
// console.log(response); // The current login status of the person.
testAPI();
} else { // Not logged into your webpage or we are unable to tell.
document.getElementById('status').innerHTML = 'Please log ' +
'into this webpage.';
}
}
function checkLoginState() { // Called when a person is finished with the Login Button.
FB.getLoginStatus(function(response) { // See the onlogin handler
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId : '717762942944749',
cookie : true, // Enable cookies to allow the server to access the session.
xfbml : true, // Parse social plugins on this webpage.
version : 'v20.0' // Use this Graph API version for this call.
});
FB.getLoginStatus(function(response) { // Called after the JS SDK has been initialized.
statusChangeCallback(response); // Returns the login status.
});
};
function testAPI() { // Testing Graph API after login. See statusChangeCallback() for when this call is made.
console.log('Welcome! Fetching your information.... ');
$("#status").empty();
FB.api('/me/accounts', function(response) {
console.log(response);
for (let i = 0; i < response.data.length; i++) {
console.log(response.data[i].id);
pages(response.data[i].id);
}
// console.log('Successful login for: ' + response.name);
// document.getElementById('status').innerHTML =
// 'Thanks for logging in, ' + response.name + '!';
});
function pages(page_id) {
FB.api(page_id+'?fields=id,name,picture', function(response) {
console.log(response);
// checkPermission(response);
});
}
// /me/permissions
}
</script>
<!-- The JS SDK Login Button -->
<!--
<fb:login-button auth_type='rerequest' scope="groups_access_member_info,public_profile,email,business_management,pages_manage_engagement,pages_manage_metadata,pages_manage_posts,pages_show_list" onlogin="checkLoginState();">
</fb:login-button> -->
<div id="fb-root"></div>
<div class="fb-login-button" auth_type='rerequest' scope="public_profile,pages_messaging,pages_manage_engagement,pages_manage_metadata,pages_manage_posts,pages_show_list,pages_read_engagement" data-width="" data-size="large" data-button-type="continue_with" data-layout="default" data-auto-logout-link="false" data-use-continue-as="true" onlogin="checkLoginState();"></div>
<!-- <div class="fb-login-button" auth_type='rerequest' scope="pages_messaging,pages_manage_engagement,pages_manage_metadata,pages_manage_posts,pages_show_list,pages_read_engagement,pages_user_gender,pages_user_timezone,pages_read_user_content" data-width="" data-size="large" data-button-type="continue_with" data-layout="default" data-auto-logout-link="false" data-use-continue-as="true" onlogin="checkLoginState();"></div> -->
<div id="status">
<span id="user_name"></span>
</div>
<!-- Load the JS SDK asynchronously -->
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
// $.ajax({
// url: "https://graph.facebook.com/{user-id}/accounts?access_token={user-access-token}",
// context: document.body
// }).done(function() {
// $( this ).addClass( "done" );
// });
</script>
</body>
</html>
|