Hello guys so I’m trying to get a list of liked pages by the user. first of all this is how the informations looks like :
{
"likes": {
"data": [
{
"name": "Page Name Here",
"id": "Page id",
"created_time": "Date"
},
{
"name": "Page Name Here",
"id": "Page id",
"created_time": "Date"
},
{
"name": "Page Name Here",
"id": "Page id",
"created_time": "Date"
}
....
....
....
}
This is my code :
loginButton.setReadPermissions("user_likes");
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GetPagesUrl = "https://graph.facebook.com/v2.4/me?fields=likes.limit(10000){name}&access_token=" + loginResult.getAccessToken().getToken();
JSONObject js = new JSONObject(get_json(GetPagesUrl));
JSONArray jarray = js.getJSONArray("data");
for(int i = 0; i < jarray.length(); i++){
// do whatever with jarray.getJSONObject(i).getJSONString("name");
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
}
});
This is the code of function get_json() used :
public JSONObject getJson(String url){
InputStream is = null;
String result = "";
JSONObject jsonObject = null;
// HTTP
try {
HttpClient httpclient = new DefaultHttpClient(); // for port 80 requests!
HttpPost httppost = new HttpPost(url);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch(Exception e) {
return null;
}
// Read response to string
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf-8"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch(Exception e) {
return null;
}
// Convert string to object
try {
jsonObject = new JSONObject(result);
} catch(JSONException e) {
return null;
}
return jsonObject;
}
**unfortunately im testing my app on a real device because i couldnot create AVD so i cant tell you what kinf of error i get **
Thanks :)