如何在facebook SDK Android中获取用户的Facebook个人资料图片 [英] How to get facebook profile picture of user in facebook SDK Android
问题描述
我使用以下代码 p>
private void onSessionStateChange(Session session,SessionState state,
异常异常){
if(session.isOpened ){
Request.newMeRequest(session,new Request.GraphUserCallback(){
@Override
public void onCompleted(GraphUser user,Response response){
if(user!= null){
try {
URL imgUrl = new URL(http://graph.facebook.com/
+ user.getId()+/ picture?type = large );
InputStream in =(InputStream)imgUrl.getContent();
位图位图= BitmapFactory.decodeStream(in);
//位图位图= B itmapFactory.decodeStream(imgUrl //尝试这也
//。openConnection()。getInputStream());
} catch(Exception e){
e.printStackTrace();
}
}
}
})。executeAsync();
}
}
当我使用直接链接然后它的工作。 p>
imgUrl =新的URL(https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-ash3/t39。 2365-6 / 851558_160351450817973_1678868765_n.png);
我也是这样也 Graph API参考
自动重定向原始和重定向协议相同时,会自动工作。
所以,尝试加载 https 而不是 http : https://graph.facebook.com/USER_ID/picture ;因为图片的网址是 https://fbcdn-profile-a.akamaihd.net/ 。 ...
然后 BitmapFactory.decodeStream
将再次工作。
I used facebook 3.6 sdk . i want to get profile picture from graph user , last time i got image but now it returns null Bitmap.
I used following code
private void onSessionStateChange(Session session, SessionState state,
Exception exception) {
if (session.isOpened()) {
Request.newMeRequest(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
try {
URL imgUrl = new URL("http://graph.facebook.com/"
+ user.getId() + "/picture?type=large");
InputStream in = (InputStream) imgUrl.getContent();
Bitmap bitmap = BitmapFactory.decodeStream(in);
//Bitmap bitmap = BitmapFactory.decodeStream(imgUrl // tried this also
//.openConnection().getInputStream());
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).executeAsync();
}
}
When i use direct link then it works.
imgUrl = new URL("https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-ash3/t39.2365-6/851558_160351450817973_1678868765_n.png");
i refered this also Graph API Reference
Auto redirection works automatically when original and redirected protocols are same.
So, 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/...."
Then BitmapFactory.decodeStream
shall work again.
这篇关于如何在facebook SDK Android中获取用户的Facebook个人资料图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!