我从Facebook好友列表中检索ID,姓名,用户名;它与Facebook应用程序ID使用时工作正常“21484349 ......”,当我运行不同的Facebook应用程序ID这是给同一代码:从Facebook好友列表中检索用户名属性
com.facebook.android.FacebookError: (#100) Unknown fields: username.
以下是我的代码
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();
运行此代码时,它可以正常工作,但是当我更改应用程序标识时它不起作用。我在Facebook开发者中创建了应用程序并获得了应用程序ID。
有你(在可用字段列表
username
不)为新的Facebook应用程序设置HashKey? –