F SDK 4.0.0:来自facebook的GraphRequest返回null

时间:2015-04-19 18:09:04

标签: android facebook facebook-graph-api

我有以下代码,我想要获得的是用户的朋友姓名,用户的朋友个人资料图片和用户的朋友facebook id

public void testFunction(final com.facebook.AccessToken access_token){
    GraphRequest request = GraphRequest.newMeRequest(
            access_token,
            new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(
                        JSONObject object,
                        GraphResponse response) {
                    if(object != null) {
                        Log.wtf("FIRST", "JSONOBJECT: IS NULL");
                    }else {
                        Log.wtf("FIRST", "JSONOBJECT: " + object.toString());
                    }

                    if(response != null) {
                        Log.wtf("FIRST", "RESPONSE: IS NULL");
                    }else {
                        Log.wtf("FIRST","response: "+response.toString());
                    }
                }
            });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,link");
    request.setParameters(parameters);
    request.executeAsync();
}

public void getFriendsInformation(final com.facebook.AccessToken access_token) {

    GraphRequestBatch batch = new GraphRequestBatch(
            GraphRequest.newMeRequest(
                    access_token,
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(
                                JSONObject jsonObject,
                                GraphResponse response) {
                            if(jsonObject != null) {
                                Log.wtf("FIRST", "JSONOBJECT: IS NULL");
                            }else {
                                Log.wtf("FIRST", "JSONOBJECT: " + jsonObject.toString());
                            }

                            if(response != null) {
                                Log.wtf("FIRST", "RESPONSE: IS NULL");
                            }else {
                                Log.wtf("FIRST","response: "+response.toString());
                            }
                            // Application code for user
                        }
                    }),
            GraphRequest.newMyFriendsRequest(
                    access_token,
                    new GraphRequest.GraphJSONArrayCallback() {
                        @Override
                        public void onCompleted(
                                JSONArray jsonArray,
                                GraphResponse response) {
                        if(jsonArray != null) {
                            Log.wtf("SECOND", "jsonArray: IS NULL");
                        }else {
                            Log.wtf("SECOND", "jsonArray: " + jsonArray.toString());
                        }

                            if(response != null) {
                                Log.wtf("SECOND", "RESPONSE: IS NULL");
                            }else {
                                Log.wtf("SECOND","response: "+response.toString());
                            }
                        }
                    })
    );
    batch.addCallback(new GraphRequestBatch.Callback() {
        @Override
        public void onBatchCompleted(GraphRequestBatch graphRequests) {
            // Application code for when the batch finishes
        }
    });
    batch.executeAsync();
}

当我使用accessToken运行代码 IS NULL 将在指定的日志中打印。这不行吗?

0 个答案:

没有答案