编程语言
首页 > 编程语言> > android – Graphpath请求中的新Facebook SDK和OAuthException

android – Graphpath请求中的新Facebook SDK和OAuthException

作者:互联网

我在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);

解决方法:

Request req = new Request(session, “/me/friends?fields=id,name,installed,picture”,null, 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, .......

那就行了.

标签:android,facebook-graph-api,facebook-android-sdk,facebook-access-token
来源: https://codeday.me/bug/20191005/1856581.html