The global ID is not allowed. Please use the application specific ID instead

前端 未结 5 1497
醉话见心
醉话见心 2020-12-14 10:48

In Graph API 2.0

When I using new graph api to access my friends information, I got the message below.

Here, xxx is an user id.

{
  \"error\"         


        
相关标签:
5条回答
  • 2020-12-14 11:01

    It's because you are using the app access token instead of user access token

    Try the user token from this page:

    If that works you need to think about getting the user access token from your app. You can give the user a prompt and receive a code as a parameter on the redirect_uri parameter

    https://www.facebook.com/dialog/oauth?client_id={app-id}&redirect_uri={redirect-uri}
    

    After you receive that code you redeem it for a user access token with a request like this:

    GET https://graph.facebook.com/oauth/access_token?client_id={app-id}&redirect_uri={redirect-uri}&client_secret={app-secret}&code={code-parameter}
    
    0 讨论(0)
  • 2020-12-14 11:06

    For apps using API version 2.0 - you can only use the App-Scoped-ID to access data about a user on v2.0+

    If you're an existing app upgrading some calls from v1.0 to v2.0 you can continue to use the user IDs you received for your app's users - for non-users of your app you must use the app-scoped ID if you want to access their data, and make the call from the same app which was given that ID

    There's more information about how App Scoped IDs work here: https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api

    0 讨论(0)
  • 2020-12-14 11:10

    Here's an excerpt from a blog post I wrote on this topic that answers your question:

    In the simpler days of v1.0, when the Graph API reported on a user, the id value it provided was a global id number for that Facebook user. These values were “global” in the sense that they could be shared between client applications. In v2.0, all user data provided by the /user endpoint and its children use application-specific ids. These ids are a unique identifier not just of the Facebook user, but of the client-user pair. This mean that you can’t share user ids between applications. (Though Facebook does provide an API for mapping between applications that are part of single organization.)

    An important consequence of this fact is that the user ids recognized by the Facebook applications you use for development will not match the ones your production app recognizes. So, if you store your users’ Facebook ids in your database in production, you won’t be able to match up users in that database with data returned from the API in development. That’s annoying!

    And there’s no way around it. You’ll just have to query for a few of your friends from the development app and manually overwrite their stored Facebook ids in your development database. This will give you a few exemplars to develop against.

    0 讨论(0)
  • 2020-12-14 11:20

    To stop easily this issue, I just added "version : 'v1.0' " in my FB.init like this:

    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    : 'v1.0' // use version 2.0
      });
    };
    

    Of course this is temporary and need to look through the different documentations as suggested by Asymmetric

    0 讨论(0)
  • 2020-12-14 11:26

    Global ID is your user ID, application specific ID is ID you are able to access (nobody knows)! This message means that Facebook doesn't authenticate your application with permission to access your profile! In other words, you need to provide access token for your user, giving the application appropriate permissions to access your data. You can obtain manually short-term access token from Graph API Exlorer here https://developers.facebook.com/tools/explorer To access your friends info, you must give user_friends permission. More about access tokens and their life is here: https://developers.facebook.com/docs/facebook-login/access-tokens

    0 讨论(0)
提交回复
热议问题