Android: Use Glide to load Facebook Photo URL

陌路散爱 提交于 2019-12-25 06:29:39

问题


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

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!


回答1:


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


来源:https://stackoverflow.com/questions/38358274/android-use-glide-to-load-facebook-photo-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!