I want to get page id from Facebook on custom page tab click. Here is the code, i am working with. Is this right way to get page id from the Facebook. I am able to get access token and user id values using this code. Any help is greatly appreciated.
window.fbAsyncInit = function () {
FB.init({
appId: 'xxxxxxxxx',
status: true,
cookie: true,
xfbml: true
});
FB.Event.subscribe('auth.authResponseChange', function (response) {
// Here we specify what we do with the response any time this event occurs.
if (response.status === 'connected') {
} else if (response.status === 'not_authorized') {
//FB.login();
} else {
//FB.login();
}
});
};
// Load the SDK asynchronously
(function (d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
} (document));
$('.btnclick').click(function () {
fblogin();
});
function fblogin() {
//FB.login();
FB.login(function (response) {
if (response.authResponse) {
var sq = FB.getAuthResponse()['signedRequest'];
var data = sq.split('.')[1];
data = JSON.parse(atob(data));
alert(data);
} else {
alert('User cancelled login or did not fully authorize.');
}
}, { scope: 'user_location,user_hometown,user_photos,friends_photos,friends_location,friends_hometown,email,user_likes,publish_actions,manage_pages', display: 'popup' });
}
Step 1 : get manage_pages permission
step 2 :
'/me?fields=accounts' - account is used to get fb pageid
For Getting page Detail form page id