Android和Facebook的:如何获得的图像记录在用户 [英] Android and Facebook: How to get picture of logged in User

查看:257
本文介绍了Android和Facebook的:如何获得的图像记录在用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的是官方Facebook SDK在我的Andr​​oid应用程序。当用户登录时,我可以得到uid和facebook的用户名像这样:

I use the official Facebook SDK in my Android Application. After the user logs in, I can get the uid and the name of the facebook user like so:

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");

我也知道,我可以访问个人资料图片与链接:

I also know that the I can access the profile picture with those links:

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

我喜欢用这个code到geht资料图片:

I would love to use this code to geht the profile picture:

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;
}

但它只是不会工作。我总是得到以下错误:

But it just wont work. I always get the following error:

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

和我并不能解决这个问题。这似乎是相当复杂的(看<一href="http://stackoverflow.com/questions/3117896/problems-with-httpclient-and-selfsigned-certificates">here或<一href="http://stackoverflow.com/questions/2642777/android-trusting-all-certificates-using-httpclient-over-https">here).那么,什么其他的选择有获得Facebook的用户成功地登录到我的应用程序的图片吗?

And I cant solve this issue. It seems to be rather complicated(look here or here). So what other options are there to get the picture of a facebook user that successfully logged into my application?

推荐答案

请求(ME /图片)抛出一个错误,因为服务器会返回一个302(重定向到图片的URL)和Facebook的SDK不处理这个问题。

request("me/picture") throws an error because the server returns a 302 (redirect to the image url) and the facebook sdk does not handle this.

这篇关于Android和Facebook的:如何获得的图像记录在用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆