【问题标题】:Wrong response from Facebook Graph when fetching page profile获取页面配置文件时来自 Facebook Graph 的错误响应
【发布时间】:2014-05-30 03:35:27
【问题描述】:

我有一种方法可以根据页面用户名从 facebook 获取页面配置文件。方法如下:

  public static void fetchProfile(Context context, String username, Request.Callback callback){
            String graphPath = BASE_URL + username;
            Log.v("FacebookController","tungtran profile:"+graphPath);
            Session session = Session.getActiveSession();
            Request request = new Request(session, graphPath, null, HttpMethod.GET, callback);
            Request.executeBatchAsync(request);
        }

  private void fetchAProfile(String username) {
        showWaiting("Loading profiles");
        Request.Callback callback = new Request.Callback() {
            @Override
            public void onCompleted(Response response) {
                FlyApp.log("tungtran profile - response:" + response.toString());
                hideWaiting();
            }
        };
        fetchProfile(this, username, callback);
    }

我在课堂上打电话:

fetchAProfile("ChelseaFC");

它之前运行良好,但由于某些原因它几天前无法运行。 Logcat 中的日志显示如下图路径:

https://graph.facebook.com/ChelseaFC

而且反应看起来很奇怪:

    {Response:  responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"id":"https:\/\/graph.facebook.com\/v2.0\/ChelseaFC"}}, error: null, isFromCache:false}

如果我将路径粘贴到 Facebook Graph API Explorer 或浏览器上,请求会返回非常不同的响应。

查看链接 https://graph.facebook.com/ChelseaFC

我花了几天时间搜索这个问题,但我没有运气。

有人知道我遇到了什么问题吗?提前感谢您的帮助。

【问题讨论】:

  • 怎么了?看起来你得到了一个 graphObject。
  • 是的,我收到了回复,但它应该返回完整的 JSON 信息作为链接:link
  • 为什么应该是JSON?您正在使用 Android SDK,因此您得到的是一个 Response 对象,您可以在 developers.facebook.com/docs/reference/android/3.0/class/… 阅读该对象。如果你想要底层的 JSON,你必须做 response.getGraphObject().getInnerJSONObject() 这将返回一个 JSONObject
  • 我不是指 JSON 或 Response 对象。我的意思是在 android 代码中执行与 Graph API 之间的差异响应。 {响应:responseCode:200,graphObject:GraphObject{graphObjectClass=GraphObject,state={"id":"https:\/\/graph.facebook.com\/v2.0\/ChelseaFC"}},错误:null, isFromCache:false} 与浏览器下方链接的区别:graph.facebook.com/ChelseaFC
  • 如果您不想要 JSON 或 Response 对象。你想要什么?

标签: android facebook facebook-graph-api user-profile


【解决方案1】:

还是谢谢你,

我解决了这个问题。

问题出在 String graphPath = BASE_URL + username;

我们不需要它。

我将方法更改如下:

public static void fetchProfile(Context context, String username, Request.Callback callback){
            Session session = Session.getActiveSession();
            Request request = new Request(session, username, null, HttpMethod.GET, callback);
            Request.executeBatchAsync(request);
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 2012-04-26
    • 2013-06-23
    • 1970-01-01
    • 2012-11-15
    相关资源
    最近更新 更多