Android : friend likes not coming in graph api in adroid

on Saturday, August 9, 2014


I am trying to get the friend likes in graph api through android app. I am able to get the friend id,name without specifying fields attribute. (like this "/me/friends")



Session.openActiveSession(this, true, new Session.StatusCallback() {

@Override
public void call(Session session, SessionState state,
Exception exception) {
// TODO Auto-generated method stub
Log.d("zumbvare", session.getPermissions().toString());

if (session.isOpened()){

Request.newMeRequest(session, new Request.GraphUserCallback() {

// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {


/*TextView welcome = (TextView) findViewById(R.id.welcome);
welcome.setText("Hello " + user.getName() + "!");*/
}
}
}).executeAsync();

new Request(
session,
"/me/friends",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */

Log.d("Zumbare", response.toString());
fbResponse=response.toString();
GraphObject graphObject = response.getGraphObject();
if (graphObject != null){
JSONObject jsonObject = graphObject.getInnerJSONObject();
try{
JSONArray array = jsonObject.getJSONArray("data");
Friend f;
for (int i = 0; i < array.length(); i++) {

f= new Friend();
JSONObject object = (JSONObject) array.get(i);
Log.d("Zumbare", "id = "+object.get("id"));
f.setID(String.valueOf(object.get("id")));
Log.d("Zumbare", "id = "+object.get("name"));
f.setName(String.valueOf(object.get("name")));
/*JSONArray a = object.getJSONArray("likes");
Log.d("Zumbare", "likes count : "+a.length());
f.setLikes(String.valueOf(a.length()));*/
friendList.add(f);

}
Log.d("Zumbare", "Friend list count : "+friendList.size());
}catch (JSONException e) {

e.printStackTrace();
}
}
}
}
).executeAsync();
}






}




});


but if I add field attributes as "/me/friends?fields=id,name,likes" I am getting exception as



{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 2500, errorType: OAuthException, errorMessage: An active access token must be used to query information about the current user.}, isFromCache:false}


I could get the permission string log as



[public_profile, basic_info, user_relationships, user_location, user_likes, user_activities, user_friends, user_about_me, user_status, user_tagged_places]


So could someone help me how to get friends likes ?


TIA


0 comments:

Post a Comment