Question

I am retrieving id, name, username from Facebook friends list; it's working fine when using with Facebook application id "21484349....." and when am running same code with different facebook app id it is giving:

com.facebook.android.FacebookError: (#100) Unknown fields: username.

The following is my code

new AsyncTask<String, Void, String>() {
    @Override
    protected String doInBackground(String... params) {
    Set<String> fields = new HashSet<String>();
    String[] requiredFields = new String[] { "id", "name", "username","installed" };
    fields.addAll(Arrays.asList(requiredFields));
Bundle parameters = new Bundle();
 parameters.putString("fields", TextUtils.join(",", fields));
String jsonUser = null;
try {
jsonUser = mFacebook.request("me/friends",  parameters,"GET");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

return jsonUser;

}
@Override
protected void onPostExecute(String result) {
if(result != null){
JSONObject obj;
try {
obj = Util.parseJson(result);
Log.i("json Response", obj.toString());
JSONArray array = obj.optJSONArray("data");     
if (array != null) {
for (int i = 0; i < array.length(); i++) {                  
String name = array.getJSONObject(i).getString("name");
String id = array.getJSONObject(i).getString("id");
username = array.getJSONObject(i).getString("username");

}
}
}.execute();

When running this code it's working fine with one Application Id, but when I changed application id it's not working. I created application in Facebook developers and got an application id.

Was it helpful?

Solution

I guess you are using v2.0 of the Graph API with one app, and the v1.0 with the other (working) one. In this version, the field username is no longer available, see:

/me/username is no longer available.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top