安卓:获取从URL连接一个位图(graph.facebook.com)重定向到另一个网址位图、重定向、网址、URL

2023-09-07 14:40:21 作者:浪荡ぶ成瘾

我所做的一切得到一个网址,我可以得到一个Facebook用户的个人资料照片。

I have done everything to get a url where i can get the profile pic of a facebook user.

唯一的问题现在剩下的是获取图像转换为位图对象。

The only problem left now is to get that image into a bitmap object.

一直以来, http://graph.facebook.com 现在先重定向连接(因为我们可以看到网址),以 https://fbcdn-profile-a.akamaihd.net/ .. (像这样)。

Since, http://graph.facebook.com now redirects the connection first (as we can see in the url) to https://fbcdn-profile-a.akamaihd.net/... (something like this).

所以,我想问如何我可以从URL中的位图: HTTP://graph.facebook .COM / ... 重定向到 https://fbcdn-profile-a.akamaihd.net/ ...

So, i wanted to ask as to how can i get the bitmap from the url : http://graph.facebook.com/... that redirects to https://fbcdn-profile-a.akamaihd.net/...

推荐答案

您都说得有道理, http://graph.facebook.com 第一重定向连接(如我们可以在URL中看到),以 https://fbcdn-profile-a.akamaihd.net / ,按钮

You are right in saying that http://graph.facebook.com redirects the connection first (as we can see in the url) to https://fbcdn-profile-a.akamaihd.net/, but-

自动重定向自动工作在原有的和重定向协议是一样的。

auto redirection works automatically when original and redirected protocols are same.

所以,如果你尝试从 HTTPS的而不是http载入图像: https://开头图.facebook.com / USER_ID /图片;由于图片的URL为 https://fbcdn-profile-a.akamaihd.net/ ......, BitmapFactory.de codeStream 将再次合作,让你的位图。

So, if you try to load images from https instead of http : "https://graph.facebook.com/USER_ID/picture"; since image's url is "https://fbcdn-profile-a.akamaihd.net/....", BitmapFactory.decodeStream shall work again to get you the bitmap.

这里的code -

Here's the code-

URL imgUrl = new URL("http://graph.facebook.com/{user-id}/picture?type=large");
InputStream in = (InputStream) imgUrl.getContent();
Bitmap  bitmap = BitmapFactory.decodeStream(in);

希望有所帮助。祝你好运。

Hope that helps. Good luck.