我在我的应用程序中设置了facebook登录,如下所示,想法是登录然后执行GraphUserCallback
所以我们可以获取使用信息,然后传递到我自己的注册系统,这样一个用户帐户就可以了设置我的应用程序。
Request.executeMeRequestAsync(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user,
Response response) {
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
if (user != null) {
Map<String, Object> responseMap = new HashMap<String, Object>();
GraphObject graphObject = response
.getGraphObject();
responseMap = graphObject.asMap();
Log.i("FbLogin", "Response Map KeySet - "
+ responseMap.keySet());
Session session = Session.getActiveSession();
String email = null;
String token = null;
String username = null;
String gender = null;
String birthday = null;
if (responseMap.get("email") != null) {
email = responseMap.get("email").toString();
username = responseMap.get("first_name").toString()+" "+responseMap.get("last_name").toString();
gender = responseMap.get("gender").toString();
token = session.getAccessToken();
/*birthday = responseMap.get("user_birthday").toString();
Context context = getApplicationContext();
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, birthday, duration);
toast.show();*/
Intent i = new Intent(LogIn.this, FbLogin2Activity.class);
i.putExtra("Email", email);
i.putExtra("Token", token);
i.putExtra("Username", username);
i.putExtra("Gender", gender);
startActivity(i);
} else {
// Clear all session info & ask user to
// login again
if (session != null) {
session.closeAndClearTokenInformation();
}
}
}
}
});
当用户点击“登录”按钮时:
fblogin.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Session session = Session.getActiveSession();
if (session == null) {
Session.openActiveSession(LogIn.this, true,
statusCallback);
} else if (!session.isOpened()) {
session.openForRead(new Session.OpenRequest(
LogIn.this).setCallback(statusCallback)
.setPermissions(permissions)
);
}
/*Intent i = new Intent(getApplicationContext(), FbLoginActivity.class);
startActivity(i);*/
}
});
我的权限是:
/***** FB Permissions *****/
permissions = new ArrayList<String>();
permissions.add("email");
permissions.add("user_birthday");
permissions.add("user_location");
/***** End FB Permissions *****/
返回用户电子邮件并且无论用户电子邮件或位置是否都在graphusecallback响应中。
不确定我是否已经发布了所有需要的内容,所以请告诉我,但我无法解决为什么它不会返回所有内容
答案 0 :(得分:1)
用户的生日将位于birthday
字段中,用户的位置将位于location
字段中(而不是user_birthday
或user_location
)。所以
birthday = responseMap.get("birthday").toString();
location = responseMap.get("location").get("name").toString();
应该有用。