4

I can run this at facebook Graph API Explorer to get user id, User name, recent status, and profile picture,

/8794851923?fields=id,name,statuses,picture 

how to execute that in android using Facebook-SDK and get the result ?

I've tried this, but it's deprecated.

Thanks,

Community
  • 1
  • 1
barikatul
  • 171
  • 2
  • 13

2 Answers2

4

After taking a look at facebook sample SDK, I got this :

     Bundle params = new Bundle();
     params.putString("fields", "id,name,statuses");

 final String requestId = "154727011315956";

 Request request = new Request(session, requestId, params, HttpMethod.GET, new Request.Callback() {
      public void onCompleted(Response response) {
                GraphObject graphObject = response.getGraphObject();
                FacebookRequestError error = response.getError();
                if(error!=null){
                 Log.e("Error", error.getErrorMessage());
                 }

            }
        });

    Request.executeAndWait(request);
barikatul
  • 171
  • 2
  • 13
  • 1
    What if I wanted to do something like this: https://graph.facebook.com/me/photos What would the Bundle params look like? – IgorGanapolsky Dec 18 '13 at 18:42
  • can we get birthday from this – Prasad Jan 06 '15 at 13:04
  • What is the exact package of `Request` class? I include android facebook sdk into the android studio project but it is saying `cannot resolve symbol Request' – Shajeel Afzal Apr 22 '15 at 21:32
  • @ShajeelAfzal, I cant remember, also it's an old code with old facebook api, you can look into the facebook api documentation here https://developers.facebook.com/docs/android/graph – barikatul Apr 24 '15 at 09:41
  • 2
    Thanks @barikatul now as for facebook SDF 4.0.1 `Request` class is replaced by `GraphRequest` class. – Shajeel Afzal Apr 24 '15 at 10:32
0

The Graph API is the primary way to get data in and out of Facebook's social graph. It's a low-level HTTP-based API that you can use to query data, post new stories, upload photos and a variety of other tasks that an app might need to do. This guide will teach you how to accomplish all these things in the Graph API.

/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/me",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
                    System.out.println("Response::" + String.valueOf(response.getJSONObject()));

        }
    }
).executeAsync();

Here,

AccessToken.getCurrentAccessToken() >> Login user access-token

/me>> Developer's own profile info

here also applied id/name of user/page to get that info like: /joshuatreemusicfestival/posts/

null>> here pass parameters of actual getting which type of info of user/page like:

Bundle param = new Bundle();
        param.putString("fields", "message,created_time,id,full_picture,status_type,source,comments.summary(true),likes.summary(true)");

param replace null

HttpMethod.GET>> Method of request [GET, POST, DELETE]

At last onCompleted() calling & getting response which you want...!!!

For referance

Dhruv Raval
  • 4,946
  • 3
  • 29
  • 34