我用android登录facebook,单击登录按钮后,我的进度对话框显示出来,它应该显示图像,电子邮件和totalfriends。 但登录后单击按钮时,我的应用程序自动关闭。 这个问题已经解决,但是我无法访问/允许json的“生日”和“总数”朋友 创建时
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
callbackManager = CallbackManager.Factory.create();
txtBirthday = (TextView)findViewById(R.id.txtBirthday);
txtEmail = (TextView)findViewById(R.id.txtEmail);
txtFriends = (TextView)findViewById(R.id.txtFriends);
imgAvatar = (ImageView)findViewById(R.id.avatar) ;
LoginButton loginButton = (LoginButton)findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("public_profile", "email", "user_birthday", "user_friends"));
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
mDialog = new ProgressDialog(MainActivity.this);
mDialog.setMessage("Retrieveing data...");
mDialog.show();
String accesstoken = loginResult.getAccessToken().getToken();
GraphRequest graphRequest = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
mDialog.dismiss();
Log.d("response", response.toString());
getData(object);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,email,birthday,friends");
graphRequest.setParameters(parameters);
graphRequest.executeAsync();
}
});
}
获取数据
private void getData(JSONObject object) {
try {
URL profile_picture = new URL("https://graph.facebook.com/"+object.getString("id")+"/picture?width=250&height=250");
Picasso.with(this).load(profile_picture.toString()).into(imgAvatar);
txtEmail.setText(object.getString("email"));
txtBirthday.setText(object.getString("birthday"));
txtFriends.setText("Friends : "+object.getJSONObject("friends").getJSONObject("summary").getString("total_count"));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
错误消息
D /响应:{响应:responseCode:200,graphObject:{“ id”:“ 2265333940356913”,“电子邮件”:“ kiluakaze@yahoo.com”},错误:null} W / Settings:设置planes_mode_on已从android.provider.Settings.System移至android.provider.Settings.Global,返回了只读值。 W / System.err:org.json.JSONException:生日没有值
感谢您的关注