Pas*_*ein 10 ssl android facebook image
我在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");
Run Code Online (Sandbox Code Playgroud)
我也知道我可以使用这些链接访问个人资料图片:
https://graph.facebook.com/<facebookId>/picture
https://graph.facebook.com/<facebookId>/picture?type=large
Run Code Online (Sandbox Code Playgroud)
我很乐意使用此代码来查看个人资料图片:
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;
}
Run Code Online (Sandbox Code Playgroud)
但它不会工作.我总是得到以下错误:
SSL handshake failure: Failure in SSL library, usually a protocol error
Run Code Online (Sandbox Code Playgroud)
Chi*_*CID 22
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);
Run Code Online (Sandbox Code Playgroud)
ID是你的个人资料ID ...
前段时间我也遇到过这个问题.我所做的是使用异步任务下载图片,然后使用刚下载的图像设置ImageView.我将粘贴代码段:
ImageView fbUserAvatar = (ImageView) findViewById(R.id.fb_user_avatar);
private synchronized void downloadAvatar() {
AsyncTask<Void, Void, Bitmap> task = new AsyncTask<Void, Void, Bitmap>() {
@Override
public Bitmap doInBackground(Void... params) {
URL fbAvatarUrl = null;
Bitmap fbAvatarBitmap = null;
try {
fbAvatarUrl = new URL("http://graph.facebook.com/"+USER_ID+"/picture");
fbAvatarBitmap = BitmapFactory.decodeStream(fbAvatarUrl.openConnection().getInputStream());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return fbAvatarBitmap;
}
@Override
protected void onPostExecute(Bitmap result) {
fbUserAvatar.setImageBitmap(result);
}
};
task.execute();
}
Run Code Online (Sandbox Code Playgroud)
这段代码适合我.我希望它对你也有用.
小智 5
您可以请求包含您的访问令牌的直接URl:
URL MyProfilePicURL = new URL("https://graph.facebook.com/me/picture?type=normal&method=GET&access_token="+ Access_token );
Run Code Online (Sandbox Code Playgroud)
然后获取解码的BitMap并将其分配给图像视图:
Bitmap MyprofPicBitMap = null;
try {
MyprofPicBitMap = BitmapFactory.decodeStream(MyProfilePicURL.openConnection().getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MyProfilePicImageView.setImageBitmap(mIcon1);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22708 次 |
| 最近记录: |