Cannot get page like for some users

流过昼夜 提交于 2019-12-22 11:22:06

问题


I've developed a PHP app which just need to get if the user has liked a certain page.

I login the user this way:

$this->_facebook = new Facebook(array(
        'appId' => "123",
        'secret' => "346",
    ));
$this->_facebookUser = $this->_facebook->getUser();
$this->_facebook->api('/me');

and then

    $checkIfUserLikePage = $this->_facebook->api(array(
        "method" => "fql.query",
        "query" => "select uid from page_fan where uid=me() and page_id=" . $pageid,
    ));

This mostly works but for some users does not, it returns an empty array. I've checked online and my app is probably missing the *user_likes* permission. And in fact I didn't have this permission. So again I found I should add the permission, uninstall the app and retry.

So I:

  1. logged to developer.facebook.com > apps > myapp > App details > Configure App Center Permissions
  2. added "user_likes" to the User and Friend Permissions text area
  3. saved
  4. asked a test user to remove myapp
  5. asked the test user to access the app

As a result I still get an empty array for the user. What else is wrong? thanks


回答1:


Don't mistake the permissions in the app center with those you pass to your scope. When prompting the user for permissions, do you have added "user_likes" to the scope?

With the JS-SDK you do it like that for example:

FB.login(function(response) {
    // Do some fancy stuff
}, {scope: 'user_likes'});

Also make sure you have a valid user access token. Your PHP-SDK provides a method called "getAccessToken()", which returns the current access token.

You can also simply try to print the results of getUser() which returns the userID of the current user. If you get 0, you can be pretty sure that the user is not connected with your facebook app and you'll therefore not be able to use me() in FQL queries.

Also query the graph API with /{user-id}/permissions. You'll get a json object returned that contains all the permissions the user gave. Of course you need a valid connected user with your app in order to do that.

I hope I could give you some helpful advice. If nothing helped try posting more code.

Happy Coding!



来源:https://stackoverflow.com/questions/20541335/cannot-get-page-like-for-some-users

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!