【问题标题】:display Facebook page posts with it's image in android app在 android 应用程序中显示 Facebook 页面帖子及其图像
【发布时间】:2017-09-30 20:41:29
【问题描述】:

我需要帮助吗? 我开发了一个应用程序,可以查看最近 20 个 Facebook 页面提要(如果存在图片,则帖子)我使用图表 (https://graph.facebook.com/229161663845327/feed?access_token=266494063684850|799f6a5b3246ceeecae7e95af945da24&limit=20) 但它给了我一个没有图像的文本帖子结果我如何在不让 Facebook 登录应用程序的情况下显示和获取每个帖子的文本和图像

【问题讨论】:

标签: android facebook facebook-graph-api


【解决方案1】:

【讨论】:

  • 这是在 android 应用程序中没有“使用 facebook 登录”功能的情况下完成的吗?您能否突出显示您所做的步骤并在 cmets 中分享一些链接。我想读取我的页面数据并在 android 应用程序中显示,而无需使用 facebook 登录。
【解决方案2】:

感谢@sunil Sunny,我解决了这个问题,它可以正常工作,无需在您的应用中登录 Facebook, 请按照以下步骤操作:

1- 在 facebook 开发者网站中,创建新项目并获取 access_token 以用于下一步 转到graph api 并单击“Graph API Explorer”按钮 2- 使用 volley 或 http 请求或您喜欢此链接的方式向此链接发出请求

String FACEBOOKURL="https://graph.facebook.com/YOUR Facebook PageID/feed?"
        +"fields=id,story,created_time,message,full_picture&access_token=/* put your access token that you take from step 1*/&limit=15"

YOUR Facebook PageID

3- 从请求中检索的数据作为字符串可以这样转换

   JSONObject dataObj = null;
            Log.i("// url", URL.FACEBOOKURL);
            try {
                String story = "";
                String message = "";
                String created_time = "";
                String image = "";
                String id = "";
                dataObj = new JSONObject(response);
                JSONArray jdata = dataObj.getJSONArray("data");
                JSONObject jpaging = dataObj.getJSONObject("paging");
                final String previous = jpaging.getString("previous");
                final String next = jpaging.getString("next");
                for (int i = 0; i < jdata.length(); i++) {
                    JSONObject jsonObject = jdata.getJSONObject(i);
                    try {
                        message = jsonObject.getString("message");
                        story = "";
                    } catch (JSONException e) {
                        story = jsonObject.getString("story");

                        Log.i("//story", story);
                    }
                    created_time = jsonObject.getString("created_time");
                    try {
                        image = jsonObject.getString("full_picture");
                    } catch (JSONException e) {
                        image = "";
                    }
                    id = jsonObject.getString("id");
                    String[] parts = id.split("_");
                    String pageId = parts[0];
                    final String postId = parts[1];
                    Log.i("---//message", postId);
                    Log.i("---//image", image);
                    fbDataList.add(new FbData(postId, message, story, created_time, image));

我尝试捕获,因为在每一行输出数据中,它正在发生变化,例如当您的帖子只有图像并且“故事”、“消息”其中一个返回时,它会返回 full_picture,您可以在浏览器中运行链接并查看输出 json 并根据需要使用它

4- 最后你可以把输出列表放到recyclerView

我希望这会有所帮助:)

【讨论】:

  • 什么是response?请详细说明
猜你喜欢
  • 1970-01-01
  • 2014-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多