0

我试图从图表中获取用户和他的朋友的分数,但我遇到了错误。“只有创建视图层次结构的原始线程才能触及它的视图。” 执行时。

JSONArray responseJSONArray = new JSONArray(response);

我拥有所需的所有权限。我通过使用以下方法成功将分数发布到图表中:

fbParams.putString("score", "" + 555);
    Request postScoreRequest = new Request(Session.getActiveSession(),
            "me/scores",
            fbParams,
            HttpMethod.POST,
            new Request.Callback() {
...
...

当我试图得到分数时。即使从使用这种模式的浏览器

https://graph.facebook.com/{userid}/scores?access_token={app_access_token}

我有

{"data":[{"user":{"name":"MYUSERNAME","id":"MIID"},"score":555,"application":{"name":"Tomato Smasher","namespace":"tomatosmasher","id":"354552234651550"}}]}

我从以下网址获得了访问代码: https ://developers.facebook.com/tools/explorer

但在 android 应用程序中使用:

Session.getActiveSession().getAccessToken();


// Execute the HTTP Get to our server for the scores of the user's friends
                HttpClient client = new DefaultHttpClient();
                String getURL = "https://graph.facebook.com/" + currentUserFBID + "/scores?access_token=" + currentUserAccessToken;
                HttpGet get = new HttpGet(getURL);
                HttpResponse responseGet = client.execute(get);
                System.out.println("ALL GOOD2");
                // Parse the response
                HttpEntity responseEntity = responseGet.getEntity();
                String response = EntityUtils.toString(responseEntity);
                System.out.println("ALL GOOD3");
                if (!response.equals(null)) {
                    System.out.println("ALL GOOD4");
                    System.out.println(response);
                    JSONArray responseJSONArray = new JSONArray(response);  // <----------------got EXEPTION HERE
                    System.out.println("ALL GOOD4.5");
4

1 回答 1

2

您可以使用此代码使用 facebook 3.0 访问朋友分数

String fqlQuery = "SELECT value FROM score WHERE user_id = "+"Enter_User_Id_Here"+" AND app_id = "+"Enter App Id Here";

            Bundle params = new Bundle();
            params.putString("q", fqlQuery);
            Session session = Session.getActiveSession();

            Request request = new Request(session,
                    "/fql",                         
                    params,                         
                    HttpMethod.GET,                 
                    new Request.Callback(){       
                public void onCompleted(Response response) {
                    Log.i("Result: ",response.toString());

                    try{
                        GraphObject graphObject = response.getGraphObject();
                        JSONObject jsonObject = graphObject.getInnerJSONObject();

                        JSONArray array = jsonObject.getJSONArray("data");

                            JSONObject data = array.getJSONObject(0);
                            Score = data.getString("value");



                    }catch(JSONException e){
                        e.printStackTrace();
                    }
                }                  
            }); 
            Request.executeBatchAsync(request); 
于 2013-07-10T06:02:28.517 回答