图表api不返回用户电子邮件ID [英] Graph api is not returning user email id
本文介绍了图表api不返回用户电子邮件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此代码中,GraphUser不返回电子邮件ID和联系电话。
In this code GraphUser is not returning email-id and contact number.
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
// userInfoTextView.setVisibility(View.VISIBLE);
// Request user data and show the results
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
// Display the parsed user info
String email= (String) response.getGraphObject().getProperty("email");
System.out.println("yahooooooooooo "+email);
buildUserInfoDisplay(user);
}
}
});
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
private String buildUserInfoDisplay(GraphUser user) {
StringBuilder userInfo = new StringBuilder("");
// Example: typed access (name)
// - no special permissions required
userInfo.append(String.format("Name: %s\n\n",
user.getName()));
// Example: typed access (birthday)
// - requires user_birthday permission
userInfo.append(String.format("Birthday: %s\n\n",
user.getBirthday()));
userInfo.append(String.format("Birthday: %s\n\n",
user.getBirthday()));
userInfo.append(String.format("Gender: %s\n\n",
user.getProperty("gender")));
userInfo.append(String.format("Iddddddd: %s\n\n",
user.getId()));
// Example: partially typed access, to location field,
// name key (location)
// - requires user_location permission
userInfo.append(String.format("Location: %s\n\n",
user.getLocation().getProperty("name")));
// Example: access via property name (locale)
// - no special permissions required
userInfo.append(String.format("Locale: %s\n\n",
user.getProperty("locale")));
return userInfo.toString();
}
推荐答案
默认情况下,获取电子邮件,您必须指定许可的电子邮件
By default you won't get the email, for email you have to specify permission
Session.StatusCallback statusCallback = new Session.StatusCallback()
{
@Override
public void call(Session session, SessionState state, Exception exception)
{
if(session.isOpened())
{
Request.executeMeRequestAsync(session, new Request.GraphUserCallback()
{
@Override
public void onCompleted(GraphUser user, Response response)
{
if(user != null)
{
try
{
System.out.println("Graph Inner Json"+user.getInnerJSONObject());
String email = user.getInnerJSONObject().getString("email");
}
}
}
}
}
}
YourActivityName.openActiveSession(this, true, statusCallback);
这是我们的 openActiveSession()
指定权限
private static Session openActiveSession(Activity activity, boolean allowLoginUI, Session.StatusCallback statusCallback)
{
OpenRequest openRequest = new OpenRequest(activity);
openRequest.setPermissions(Arrays.asList("user_birthday", "email"));
openRequest.setCallback(statusCallback);
Session session = new Session.Builder(activity).build();
if(SessionState.CREATED_TOKEN_LOADED.equals(session.getState()) || allowLoginUI)
{
Session.setActiveSession(session);
session.openForRead(openRequest);
return session;
}
return null;
}
和 onActivityResult()
不要忘了做
if(Session.getActiveSession() != null)
{
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
这篇关于图表api不返回用户电子邮件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文