gpt4 book ai didi

android - 如何从 Facebook 获取 ParseUser 的名称?

转载 作者:搜寻专家 更新时间:2023-11-01 09:00:30 24 4
gpt4 key购买 nike

我在尝试获取通过 Facebook 登录的 Parse 用户的姓名时遇到了很大的问题。

登录工作正常,我可以在解析数据浏览器上看到用户 token ,ParseUser.getCurrentUser 返回一个 ParseUser 等等,但我不知道我能否从 facebook 获取用户名?

到目前为止我的代码是

ParseFacebookUtils.logIn(C_RegisterLogin.this, new LogInCallback()
{
@Override
public void done(ParseUser user, ParseException err)
{
progressdialog.dismiss();

if (user == null)
{
Toast toast = Toast.makeText(getApplicationContext(), "Login via Facebook failed!", Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP, 0, 20);
toast.show();
}
else
{
if (user.isNew())
{
}

List args = new ArrayList<String>();
args.add("name");
JSONObject result = new JSONObject(ParseFacebookUtils.getSession().requestNewReadPermissions(C_RegisterLogin.this, args);
String facebookname = result.optString("name");

Toast toast = Toast.makeText(getApplicationContext(), "Thanks, "+facebookname+". You are now successfully logged in!", Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP, 0, 20);
toast.show();
finish();
startActivity(new Intent(C_RegisterLogin.this, E_SelectJourney.class));
}
}
});

最佳答案

解决了它,只需要它使用来自 facebook 的 Request.executeMeRequestAsync,并且对于它的 session 参数,我使用 Parse 给我的 session :D

if (ParseFacebookUtils.getSession().isOpened())
{
Request.executeMeRequestAsync(ParseFacebookUtils.getSession(), new Request.GraphUserCallback()
{
@Override
public void onCompleted(GraphUser user, Response response)
{
if (user != null)
{
progressdialog.dismiss();
Toast toast = Toast.makeText(getApplicationContext(), "Thanks, " + user.getName() + ". You are now successfully logged in through Facebook!", Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP, 0, 20);
toast.show();
finish();
startActivity(new Intent(C_RegisterLogin.this, E_SelectJourney.class));
}
}
});
}

关于android - 如何从 Facebook 获取 ParseUser 的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15416419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com