Search code examples
javaandroidfacebook-graph-api-v2.0

Facebook API 2.1 how to query and get the data output


I am trying to get my id via the Facebook API 2.1

https://graph.facebook.com/v2.1/me&fields=id&access_token="+accesstoken

I get error 200 but no data.

Does anyone have an example how to get and extract my id, name, or any data from query 2.1?


Solution

  • that's because of me&field=id must be me?field=id

    https://graph.facebook.com/v2.1/me?fields=id&access_token=accesstoken
    

    for all public user information

    https://graph.facebook.com/v2.1/me?access_token=accesstoken
    

    i would recommend you to use Facebook SDK. see Using the Graph API

    Example graph api me request with facebook sdk:

        new Request(
            Session.getActiveSession(),
            "/me",
            null,
            HttpMethod.GET,
            new Request.Callback() {
                @Override
                public void onCompleted(Response response) {
                    GraphObject graphObject = response.getGraphObject();
                    if (graphObject != null) {
                        if (graphObject.getProperty("id") != null) {
                            String fbId = graphObject.getProperty("id").toString();
                            String userName = graphObject.getProperty("name").toString();
                        }
                    }
                }
            }
        ).executeAsync();