Facebook page access token for the page I am admin of

时间:2018-04-18 18:13:57

标签: facebook facebook-graph-api

I am using the Facebook JS code for retrieving a list of pages of which I am assigned to as an admin. I get list of all such pages but one page is somehow not showing up. I have checked all the permissions and roles, using proper app id, also the app is showing active on that page but still somehow it is not showing up in the list and I need that page for getting page access token. Also I am using manage_pages permissions in Facebook JS function.

So can someone please suggest a probable reason for the page not showing up in the list. The code I am using is below (which is completely facebook code except my app ID).

<script>
window.fbAsyncInit = function()
{
    FB.init({
        appId      : 'xxxx6xx89xx5xxx', // app id is correct i have checked
        xfbml      : true,
        version    : 'v2.12'
    });
};

(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'));

function subscribeApp(page_id, page_access_token)
{
    console.log('Subscribing page to app! ' + page_id);
    FB.api(
        '/' + page_id + '/subscribed_apps',
        'post',
        {access_token: page_access_token},
        function(response)
        {
            console.log('Successfully subscribed page', response);
        }
    );
}

// Only works after `FB.init` is called
function myFacebookLogin()
{
    FB.login(function(response)
    {
        console.log('Successfully logged in', response);

        FB.api('/me/accounts', function(response)
        {
            console.log('Successfully retrieved pages', response);

            var pages = response.data;
            var ul = document.getElementById('list');
            for (var i = 0, len = pages.length; i < len; i++) 
            for (var i=0; i < response.data.length; i++)
            {
                var page = pages[i];
                var li = document.createElement('li');
                var a = document.createElement('a');
                a.href = "#";
                a.onclick = subscribeApp.bind(this, page.id, page.access_token);
                a.innerHTML = page.name;
                li.appendChild(a);
                ul.appendChild(li);
            }
        });
    }, {scope: 'manage_pages'});
}
</script>
<button onclick="myFacebookLogin()">Login with Facebook</button>
<ul id="list"></ul>

1 个答案:

答案 0 :(得分:1)

告诉我,如果我在评论中遗漏了什么,但是afaik只能是那些东西:

  • 您有超过25个页面,因此您需要使用限制参数或分页。使用limit参数进行测试:FB.api('/me/accounts', {limit: 100}, function(response) ...

  • 您没有足够的页面

  • 权限
  • 这是一个错误,您应该将其报告给Facebook