Android和Facebook的:如何获得的图像记录在用户如何获得、图像、用户、Android

由网友(猫耳酱ギ)分享简介:我用的是官方Facebook SDK在我的Andr​​oid应用程序。当用户登录时,我可以得到uid和facebook的用户名像这样:I use the official Facebook SDK in my Android Application. After the user logs in, I can get...

我用的是官方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

和我并不能解决这个问题。这似乎是相当复杂的(看here或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.

阅读全文

相关推荐

最新文章