我正在尝试实现最新的 facebook 登录活动。我有一个主要活动和我的自定义按钮,通过点击该按钮通过 facebook 登录它应该登录获取用户详细信息、电子邮件、个人资料图片和朋友详细信息。我尝试了 facebook 给出的登录代码,它仅适用于我尝试过的基本详细信息添加权限,但电子邮件和其余部分仍然为空,但我正确获取了基本详细信息。此外,我使用的是活动而不是片段。我还如何获取其他详细信息?请帮帮我。在此先感谢。
public class new2 extends Activity {
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b=(Button)findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
loginact();
}
});
}
protected void loginact() {
// TODO Auto-generated method stub
progressDialog = ProgressDialog.show(new2.this, "loading", "loading");
new Thread(new Runnable(){
public void run(){
Session.openActiveSession(new2.this, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Request request = Request.newMeRequest(session, new GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
progressDialog.dismiss();
if (user != null) {
TextView welcome = (TextView) findViewById(R.id.textView1);
welcome.setText("Hello " + user.getName() + "!");
TextView t = (TextView) findViewById(R.id.textView1);
t.setText(user.getName() + ","
+ user.getUsername() + ","
+ user.getId() + "," + user.getLink()
+ "," + user.getFirstName()+ user.asMap().get("email"));
// String email = (String) response.getGraphObject().getProperty("email");
Log.w("user", user.toString());
Log.w("response", response.toString());
Log.w("email", user.asMap().get("email").toString());
}
}
}
);
String NAME = "name";
String ID = "id";
String PICTURE = "picture";
String EMAIL = "email";
String FRIENDS = "read_friendlists";
String FIELDS = "fields";
String REQUEST_FIELDS = TextUtils.join(",", new String[] {
ID, NAME, PICTURE, EMAIL,FRIENDS
});
Bundle parameters = new Bundle();
parameters.putString(FIELDS, REQUEST_FIELDS);
request.setParameters(parameters);
Request.executeBatchAsync(request);
}
}
});
}
}
).start();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}