Android:使用Glide加载Facebook照片URL [英] Android: Use Glide to load Facebook Photo URL
问题描述
我正在构建一个Android应用,试图让用户从Facebook引入照片.从GraphRequest中获取URL后,我尝试使用Glide将图像加载到ImageButton
中,但始终收到错误D/skia: --- skImageDecoder::Factory returned null
.这是我的代码:
I'm building an Android app in which I'm trying to let the user bring in photos from Facebook. After I grab the URLs from a GraphRequest, I'm trying to use Glide to load the image into an ImageButton
but I keep getting the error D/skia: --- skImageDecoder::Factory returned null
. Here's my code:
GraphRequest request = GraphRequest.newMeRequest(
AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
try {
String url = object.getJSONObject("photos").getJSONArray("data").getJSONObject(0).getString("link");
Glide.with(UserSettingsActivity.this).load(url).into(userOne);
} catch (Exception e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields","id,photos{link}");
request.setParameters(parameters);
request.executeAsync();
编辑-抱歉,发布后我立即意识到我实际上没有提出任何问题.有谁知道加载Facebook照片的正确方法是什么?谢谢!
EDIT - Sorry, I realized right after posting that I didn't actually ask a question. Does anyone know what the correct way to load Facebook photos is? Thanks!
推荐答案
我能够通过将photos{link}
切换为photos{source}
并返回实际的源URL来解决该问题.这是修改后的代码:
I was able to solve the problem by switching photos{link}
to photos{source}
which returns the actual source URLs. Here's the revised code:
GraphRequest request = GraphRequest.newMeRequest(
AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
try {
String url = object.getJSONObject("photos").getJSONArray("data").getJSONObject(0).getString("source");
Glide.with(UserSettingsActivity.this).load(url).into(userOne);
} catch (Exception e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields","id,photos{source}");
request.setParameters(parameters);
request.executeAsync();
这篇关于Android:使用Glide加载Facebook照片URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!