Android facebook restful graph api没有显示用户组

时间:2013-11-28 05:55:09

标签: android facebook-graph-api

我正在使用facebook graph api获取用户组,因为我正在点击网址:

https://graph.facebook.com/100003073570029/groups?access_token=CAAIOdlfN3OEBABdbIEb91hchXeMdHIYqM6fZCfQpgcVIcZB6mn9SCsnKtUSZBxGrLOCqYGX2LvulSysCW7HZCG34rXrBrfwQGmN8FzW70jNhOe588e1EfzM1J8ztxvxDZAtg5ZB0qYAvRKuBL0l0FVxv7w28mlnSd3LvLnZA6fDHskQV8k8zJF9

但这会导致空的json响应。

这是我的代码:

public static String postData(String url) {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        //HttpGet httppost = new HttpGet("https://graph.facebook.com/"+facebookId+"/groups?access_token="+accessToken);
        HttpGet httppost = new HttpGet("https://graph.facebook.com/100003073570025/groups?access_token=CAAIOdlfN3OEBABdbIEb91hchXeMdHIYqM6fZCfQpgcVIcZB6mn9SCsnKtUSZBxGrLOCqYGX2LvulSysCW7HZCG34rXrBrfwQGmN8FzW70jNhOe588e1EfzM1J8ztxvxDZAtg5ZB0qYAvRKuBL0l0FVxv7w28mlnSd3LvLnZA6fDHskQV8k8zJF7");

        String response=null;
        try {
            // Add your data
            //httppost.setEntity(new UrlEncodedFormEntity(requestParaList));

            // Execute HTTP Post Request
            HttpResponse httpResponse = httpclient.execute(httppost);
            response = request(httpResponse);
            /*
             * int status = response.getStatusLine().getStatusCode();
             * System.out.println("data posted, status = " + status);
             */
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }
        return response;
    }

以下是请求方法:

public static String request(HttpResponse response) {
    String result = "";
    try {
        InputStream in = response.getEntity().getContent();
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(in));

        StringBuilder str = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            str.append(line + "\n");
        }
        in.close();
        result = str.toString();
    } catch (Exception ex) {
        result = "Error";
    }
    return result;
}

这是堆栈跟踪:

11-28 11:48:49.533: I/System.out(17641): waiting for debugger to settle...
11-28 11:48:49.732: I/System.out(17641): waiting for debugger to settle...
11-28 11:48:49.935: I/System.out(17641): waiting for debugger to settle...
11-28 11:48:50.137: I/System.out(17641): waiting for debugger to settle...
11-28 11:48:50.338: I/System.out(17641): waiting for debugger to settle...
11-28 11:48:50.541: I/System.out(17641): debugger has settled (1401)
11-28 11:48:58.174: D/Image Button(17641): button Clicked
11-28 11:49:00.713: D/dalvikvm(17641): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)
11-28 11:49:00.717: D/dalvikvm(17641): GC_FOR_MALLOC freed 4975 objects / 294864 bytes in 29ms
11-28 11:49:04.053: W/dalvikvm(17641): threadid=8: thread exiting with uncaught exception (group=0x4001d7d0)
11-28 11:49:04.064: E/AndroidRuntime(17641): FATAL EXCEPTION: Thread-10
11-28 11:49:04.064: E/AndroidRuntime(17641): java.lang.NullPointerException
11-28 11:49:04.064: E/AndroidRuntime(17641):    at com.facebook.FacebookHandler$GroupsRequestListener.onComplete(FacebookHandler.java:661)
11-28 11:49:04.064: E/AndroidRuntime(17641):    at com.facebook.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:245)
11-28 11:51:39.892: W/ActivityThread(17693): Application com.example.fblogindev is waiting for the debugger on port 8100...
11-28 11:51:39.912: I/System.out(17693): Sending WAIT chunk
11-28 11:51:39.927: I/dalvikvm(17693): Debugger is active
11-28 11:51:40.111: I/System.out(17693): Debugger has connected
11-28 11:51:40.111: I/System.out(17693): waiting for debugger to settle...
11-28 11:51:40.314: I/System.out(17693): waiting for debugger to settle...
11-28 11:51:40.514: I/System.out(17693): waiting for debugger to settle...
11-28 11:51:40.714: I/System.out(17693): waiting for debugger to settle...
11-28 11:51:40.916: I/System.out(17693): waiting for debugger to settle...
11-28 11:51:41.119: I/System.out(17693): waiting for debugger to settle...
11-28 11:51:41.318: I/System.out(17693): waiting for debugger to settle...
11-28 11:51:41.521: I/System.out(17693): waiting for debugger to settle...
11-28 11:51:41.728: I/System.out(17693): debugger has settled (1442)
11-28 11:51:43.154: D/Image Button(17693): button Clicked
11-28 11:51:45.724: D/dalvikvm(17693): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)
11-28 11:51:45.732: D/dalvikvm(17693): GC_FOR_MALLOC freed 5016 objects / 296224 bytes in 29ms
11-28 11:51:50.494: W/dalvikvm(17693): threadid=8: thread exiting with uncaught exception (group=0x4001d7d0)
11-28 11:51:50.560: E/AndroidRuntime(17693): FATAL EXCEPTION: Thread-10
11-28 11:51:50.560: E/AndroidRuntime(17693): java.lang.NullPointerException
11-28 11:51:50.560: E/AndroidRuntime(17693):    at com.facebook.FacebookHandler$GroupsRequestListener.onComplete(FacebookHandler.java:661)
11-28 11:51:50.560: E/AndroidRuntime(17693):    at com.facebook.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:245)

这是我得到此异常的方法:

public void request(final String graphPath, final Bundle parameters,
            final String httpMethod, final RequestListener listener,
            final Object state) {
        new Thread() {
            @Override
            public void run() {
                try {
                    String resp = fb.request(graphPath, parameters, httpMethod);
                    listener.onComplete(resp, state);
                } catch (FileNotFoundException e) {
                    listener.onFileNotFoundException(e, state);
                } catch (MalformedURLException e) {
                    listener.onMalformedURLException(e, state);
                } catch (IOException e) {
                    listener.onIOException(e, state);
                }
            }
        }.start();
    }

在上面的方法中,状态变为null。

0 个答案:

没有答案