[英]In Android, Facebook API V2.4 is not returning email id whereas V2.3 is returning. How to get email id in V2.4?
When I wrote the following code for API V2.3 this was giving me all details including email id. 当我为API V2.3编写以下代码时,这为我提供了所有详细信息,包括电子邮件ID。 And now the same code is not giving me email id. 现在,相同的代码没有给我发送电子邮件ID。 What can I can do to get email id? 我该怎么办才能获得电子邮件ID?
oncreate(..)
{
.
.
EMAIL_PERMISSION = new ArrayList<String>();
EMAIL_PERMISSION.add("email");
uiLifecycleHelper = new UiLifecycleHelper(this, statusCallback);
uiLifecycleHelper.onCreate(savedInstanceState);
Session.openActiveSession(this, true, EMAIL_PERMISSION,
statusCallback);
// callback when session changes state
Session.StatusCallback statusCallback = new StatusCallback()
{
@Override
public void call(Session session, SessionState state, Exception
exception)
{
// Checking whether the session is opened or not
if (state.isOpened())
{
} else
{
if (state.isClosed())
{
}
Log.d(TAG, state.toString());
}
}
};
// Method to get user facebook profile
void getUserFacebookProfile(Session session, final boolean finish)
{
// Checking whether the session is opened or not
if (session.isOpened())
{
// Sending request to the facebook to get user facebook profile
Request.newMeRequest(session, new GraphUserCallback()
{
@Override
public void onCompleted(GraphUser user, Response response)
{
if (user != null)
{
// To get network user id
String networkUserid = user.getId();
// To get user first name
String fname = user.getFirstName();
// To get user last name
String lname = user.getLastName();
// To get user middle name
String mname = user.getMiddleName();
// String email = user.getProperty("email").toString();
String email = response.getGraphObject().getProperty("email")
.toString();
}
Now the above code gave me all details including email id for V2.3, now i'm not able to get email id. 现在,上面的代码为我提供了所有详细信息,包括V2.3的电子邮件ID,现在我无法获取电子邮件ID。 Please let me know solution. 请让我知道解决方案。 Thanks. 谢谢。
public class LoginFacebook {
CallbackManager callbackManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
public void openFB() {
LoginManager.getInstance().logInWithReadPermissions(activity,
Arrays.asList("read_stream", "user_photos", "email", "user_location"));
// Login Callback registration
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(final LoginResult loginResult) {
new GraphRequest(AccessToken.getCurrentAccessToken(),
"/me", null, HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(
GraphResponse response) {
/* handle the result */
try {
//GET USER INFORMATION
JSONObject json = response.getJSONObject();
String email = json.getString("email");
String fullName = json.getString("name");
String accessToken = loginResult.getAccessToken().getToken();
int type = 1;
String lastUpdate = json.getString("updated_time");
String user_id = json.getString("id");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).executeAsync();
GetSnsPost getSnsPost = GetSnsPost.getInstance(activity);
getSnsPost.getFacebookPosts();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException exception) {
}
});
}
public void loginFacebook(View v){
openFB();
}
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
Since session have been deprecated long time ago, I don't use it anymore. 由于会话很久以前已被弃用,因此我不再使用它。 I get user information this way. 我通过这种方式获取用户信息。 Hope this code will solve your problem ;) 希望这段代码能解决您的问题;)
Bundle params = new Bundle(); Bundle参数= new Bundle(); params.putString("fields", "id,name,email,birthday,first_name,last_name"); params.putString(“ fields”,“ id,name,email,birthday,first_name,last_name”);
new GraphRequest( AccessToken.getCurrentAccessToken(), AccessToken.getCurrentAccessToken().getUserId(), params, HttpMethod.GET, new GraphRequest.Callback() { 新的GraphRequest(AccessToken.getCurrentAccessToken(),AccessToken.getCurrentAccessToken()。getUserId(),params,HttpMethod.GET,新的GraphRequest.Callback(){
@Override
public void onCompleted(
GraphResponse response) {
System.out.println("\n J S O N :"
+ response.toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).executeAsync();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.