I am developing an android app in which I want to fetch all the friends which are using the same app, using facebook sdk 4.1 , I tried to find latest tutorials but didn't find anyone... I tried to use GraphRequestBatch but onCompleted is never called, please help!!
package com.miivideos;
import java.util.Arrays;
import java.util.List;
import org.json.JSONArray;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.example.miivideos.R;
import com.facebook.AccessToken;
import com.facebook.CallbackManager;
import com.facebook.GraphRequest;
import com.facebook.GraphRequestBatch;
import com.facebook.GraphResponse;
public class FriendList extends SherlockFragmentActivity {
private static final String TAG = "FriendList";
public static final List<String> PERMISSIONS = Arrays.asList("publish_actions", "email", "user_location","user_friends");
private CallbackManager callbackManager;
AccessToken accesstoken=AccessToken.getCurrentAccessToken();
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.friend_list);
android.app.ActionBar ab = getActionBar();
ColorDrawable colorDrawable = new ColorDrawable(getResources()
.getColor(R.color.green));
ab.setBackgroundDrawable(colorDrawable);
callbackManager = CallbackManager.Factory.create();
new GetFriendList().execute();
}
class GetFriendList extends AsyncTask<String, String, String> {
ProgressDialog pdig = new ProgressDialog(FriendList.this);
@Override
protected String doInBackground(String... params) {
Log.i(TAG, "Working in background...");
//LoginManager.getInstance().logInWithReadPermissions(FriendList.this, Arrays.asList("user_friends"));
//Log.i(TAG,"Having token for: "+String.valueOf(AccessToken.getCurrentAccessToken().getPermissions()));
GraphRequestBatch batch = new GraphRequestBatch(
GraphRequest.newMyFriendsRequest(accesstoken,
new GraphRequest.GraphJSONArrayCallback() {
@Override
public void onCompleted(JSONArray jarray,
GraphResponse response) {
Log.i(TAG, "onCompleted: jsonArray "
+ jarray);
Log.i(TAG, "onCompleted: response "
+ response);
Toast.makeText(FriendList.this, "result:"+jarray.toString(), Toast.LENGTH_LONG).show();
}
}));
batch.addCallback(new GraphRequestBatch.Callback() {
@Override
public void onBatchCompleted(GraphRequestBatch batch) {
Log.i(TAG, "onbatchCompleted: jsonArray "
+ batch);
}
});
batch.executeAsync();
return null;
}
@Override
protected void onPostExecute(String result) {
if (pdig.isShowing())
pdig.dismiss();
super.onPostExecute(result);
}
@Override
protected void onPreExecute() {
pdig.setTitle("Fetching");
pdig.setMessage("Fetching facebook friends...");
//pdig.show();
Log.i(TAG, "Starting...");
super.onPreExecute();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}