获取出生和镇/市日期从Facebook SDK GraphUserCallback [英] Get Date of Birth and Town/City from Facebook SDK GraphUserCallback
问题描述
我的Facebook洛建立我的应用程序如下图所示范围内,这个想法是登录,然后执行 GraphUserCallback
所以我们可以得到使用信息,然后传递给我的自己注册系统,以便用户帐户可以设置为我的应用程序。
I have facebook loggin set up within my app like below, the idea is to login and then do a GraphUserCallback
so we can get the use information and then pass to my own register system so a user account can be set up for my app.
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响应
The users email is returned and works however neither the users email or location is in the graphusecallback response.
不知道如果我已经发布所有需要的,所以让我知道,但我不明白为什么它没有返回的一切
Not sure if I have posted all that is needed so let me know but I cant work out why its not returning everything
推荐答案
用户的生日会在生日
字段,以及用户的位置将在位置
字段(而非 user_birthday
或 USER_LOCATION
)。因此,
The user's birthday will be in the birthday
field, and the user's location will be in the location
field (as opposed to user_birthday
or user_location
). So
birthday = responseMap.get("birthday").toString();
location = responseMap.get("location").get("name").toString();
应该工作。
这篇关于获取出生和镇/市日期从Facebook SDK GraphUserCallback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!