Android : Getting a Bitmap from a url connection (graph. facebook.com)重定向到另一个网址

标签 android facebook facebook-graph-api bitmap url-redirection

我已尽一切努力获得一个 url,我可以在其中获取 facebook 用户的个人资料照片。

现在剩下的唯一问题是将该图像放入位图对象中。

因为,http://graph.facebook.com现在首先将连接重定向(正如我们在 url 中看到的那样)到 https://fbcdn-profile-a.akamaihd.net/ ...(类似这样的事情)。

所以,我想问一下如何从 url 获取位图:http://graph.facebook.com/ ... 重定向到 https://fbcdn-profile-a.akamaihd.net/ ...

最佳答案

你说得对 http://graph.facebook.com首先将连接重定向(正如我们在 url 中看到的那样)到 https://fbcdn-profile-a.akamaihd.net/ , 但是-

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

因此,如果您尝试从 https 而不是 http 加载图像:“https://graph.facebook.com/USER_ID/picture ”;由于图像的 url 是“https://fbcdn-profile-a.akamaihd.net/ ....”,BitmapFactory.decodeStream 将再次工作以获取位图。

这是代码-

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

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

关于Android : Getting a Bitmap from a url connection (graph. facebook.com)重定向到另一个网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22928137/

相关文章:

php - 使用 Graph API 删除 Facebook 帖子 - 无法正常工作

node.js - Passport.js 和 Facebook Graph API

android - Android 设备上的加密

android - 如何衡量 Phonegap UI 性能?

php - API 错误代码 : 100 facebook OpenGraph

Facebook 访问 token 已过期

facebook - 更改 Facebook 链接上的缩略图

android - 在空属性上改造 SimpleXMLConverter NumberFormatException

android - Notification contentView 和 bigContentView 在 Android 7 中为 null

ios - 如何使用 SDK 3.1 在 iOS 上获取 native Facebook 登录?