新的Facebook SDK和OAuthException在Graphpath请求(New Face

2019-07-05 11:07发布

我看到了关于这个问题与旧版本的SDK的答案的布赫,我似乎无法弄清楚,为什么这是发生在我身上。

如果我使用此代码,它完美:

String QUERY = "select uid, name, pic_square, is_app_user from user where uid in (select uid2 from friend where uid1 = me())";
protected void getFacbookFirends() {
    Bundle params = new Bundle();
    params.putString("q", QUERY);
    final Request req = new Request(getSession(), "/fql", params, HttpMethod.GET, fbCallback);

    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            Request.executeBatchAsync(req);
        }
    });
}

但这是非常难看,所以我试图用这个代替:

Session session = Session.getActiveSession();
if (session == null) {
    session = new Session(getActivity());
}
if (session != null && session.isOpened()) {
    Request req = Request.newGraphPathRequest(session, "/me/friends?fields=id,name,installed,picture",
            new Callback() {
                @Override
                public void onCompleted(Response response) {
                            Log.w("FriendsListFragment.Facebook.onComplete", response.toString());
                }
            });
    Request.executeBatchAsync(req);
}

我的理解,这是完全相同的请求,并应运行只是以同样的方式,而是获得我想要的回应,我得到这个Response对象:

{Response:  
responseCode: 400, 
graphObject: null, 
error: {FacebookServiceErrorException: 
    httpResponseCode: 400, 
    facebookErrorCode: 2500, 
    facebookErrorType: OAuthException, 
    message: An active access token must be used to query information about the current user.
    }, 
isFromCache:false
}

关于我怎样才能使这项工作很好的任何想法?

编辑:

我试图运行这些代码,并仍然得到了相同的结果:

Request req = new Request(session, "/me/friends?fields=id,name,installed,picture",null, HttpMethod.GET,
        new Callback() {

            @Override
            public void onCompleted(Response response) {
                        Log.w("FriendsListFragment.Facebook.onComplete", response.toString());
            }
        });
Request.executeBatchAsync(req);

Answer 1:

请求REQ =新的请求(会话 “/我/朋友?场= ID,名字,安装,图片”,空,HttpMethod.GET,.......

不要把整个路径图中的路径参数,一切之后? 应该是你设置为null PARAMS参数。 试试这个:

Bundle params = new Bundle();
params.putString("fields", "id,name,installed,picture");
Request req = new Request(session, "me/friends", params, HttpMethod.GET, .......

这将这样的伎俩。



文章来源: New Facebook SDK and OAuthException in Graphpath requests