Java 在我的Android类中从Facebook获取用户信息
在阅读了一些与这个主题相关的帖子后,我无法解决我的疑问 在我的应用程序中,我使用Facebook(Registration.class)登录,应用程序在MainActivity.class中启动 在这个类中,我想获取一些关于用户的信息,比如“user\u ID”来获取图像配置文件user和“user\u first\u name”,这两个信息都有助于将这些信息放在导航抽屉中 我的问题是,我在Registration.class中使用以下代码获取此信息:Java 在我的Android类中从Facebook获取用户信息,java,android,facebook,Java,Android,Facebook,在阅读了一些与这个主题相关的帖子后,我无法解决我的疑问 在我的应用程序中,我使用Facebook(Registration.class)登录,应用程序在MainActivity.class中启动 在这个类中,我想获取一些关于用户的信息,比如“user\u ID”来获取图像配置文件user和“user\u first\u name”,这两个信息都有助于将这些信息放在导航抽屉中 我的问题是,我在Registration.class中使用以下代码获取此信息: profileTracker = new
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
// App code
Log.i("PERFIL_NAME", Profile.getCurrentProfile().getFirstName());
Log.i("PERFIL_FOTO", Profile.getCurrentProfile().getProfilePictureUri(100, 100).toString());
Log.i("USER_ID", Profile.getCurrentProfile().getId());
}
};
但我不知道如何才能在MainActivity.class上获得它
如果我以同样的方式使用它,我会得到null。另外,我已经用一个Intent进行了测试,但它不起作用,因为它也是null(我假设Intent在profileTracker()之前执行)
此外,我在MainActivity中尝试了一些方法,如:
public void putImageProfile() {
URL imgUrl = null;
try {
imgUrl = new URL("http://graph.facebook.com/'user_ID'/picture?type=large");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream in = null;
try {
in = (InputStream) imgUrl.getContent();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap bitmap = BitmapFactory.decodeStream(in);
img_profile.setImageBitmap(bitmap); //ImageView in NavDrawer
}
('user_ID'是我在Facebook上手动编写的用户ID档案1000098…),但它不能正常工作
总之,我想在MainActivity.class中获取“user\u ID”和“user\u name”。。。之后,获取带有“用户ID”的图像配置文件
非常感谢。检查一下,会有帮助的you@Tufan我已经测试了你链接中的代码但是,如果我把代码放在Registration.class中,那么我如何在main activity.class中获取信息?这真的很关键..当你获取信息时,你可以做什么,你可以保存在SharedReferences中..并使用它进行播放..但是通过你的链接,我可以获取我已经知道的信息,我已经使用'profileTracker()'。。。我如何在两个类中使用SharedReference来实现这一点?谢谢