gpt4 book ai didi

安卓和 Facebook : How to get picture of logged in User

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:52:13 26 4
gpt4 key购买 nike

我在我的 Android 应用程序中使用官方 Facebook SDK。用户登录后,我可以像这样获取 uid 和 facebook 用户的名称:

Facebook mFacebook = new Facebook(APP_ID);
// ... user logs in ...
//String jsonUser = mFacebook.request("me/picture"); // throws error
String jsonUser = mFacebook.request("me");
JSONObject obj = Util.parseJson(jsonUser);
String facebookId = obj.optString("id");
String name = obj.optString("name");

我也知道我可以通过这些链接访问个人资料图片:

https://graph.facebook.com/<facebookId>/picture 
https://graph.facebook.com/<facebookId>/picture?type=large

我很乐意使用此代码获取个人资料图片:

public static Drawable getPictureForFacebookId(String facebookId) {

Drawable picture = null;
InputStream inputStream = null;

try {
inputStream = new URL("https://graph.facebook.com/" + facebookId + "/picture").openStream();
} catch (Exception e) {
e.printStackTrace();
return null;

}
picture = Drawable.createFromStream(inputStream, "facebook-pictures");

return picture;
}

但它就是行不通。我总是收到以下错误:

SSL handshake failure: Failure in SSL library, usually a protocol error

我无法解决这个问题。它似乎相当复杂(看 herehere )。那么还有哪些其他选项可以获取成功登录到我的应用程序的 Facebook 用户的照片?

最佳答案

ImageView user_picture;
userpicture=(ImageView)findViewById(R.id.userpicture);
URL img_value = null;
img_value = new URL("http://graph.facebook.com/"+id+"/picture?type=large");
Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
userpicture.setImageBitmap(mIcon1);

其中 ID 是您的个人资料 ID...

关于安卓和 Facebook : How to get picture of logged in User,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4461150/

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