FreeBase Android Query仅返回1个结果

时间:2014-06-11 13:12:35

标签: android freebase

我正在构建一个Android应用程序。我尝试从https://www.googleapis.com/freebase/v1/search

获取数据

代码:

    query = "'[{'" + 
                       "'name': null,'" + 
                       "'mid':  null,'" + 
                       "'/location/location/geolocation': [{'" + 
                           "'longitude': null,'" + 
                           "'latitude':  null'" + 
                           "'}],'" + 
                    "'type': '/travel/tourist_attraction'" + 
                    "'}]'".replace('\'', '"');;

                nameValuePairs.add(new BasicNameValuePair("query", query));
                nameValuePairs.add(new BasicNameValuePair("limit", "10"));
                nameValuePairs.add(new BasicNameValuePair("indent", "true"));
                nameValuePairs.add(new BasicNameValuePair("key", FreeBase.API_KEY));

                // Making a request to url and getting response
                String jsonStr = sh.makeServiceCall(url, FreeBaseServiceHandler.GET, nameValuePairs);


public String makeServiceCall(String url, int method,
            List<NameValuePair> params) {
        try {
            // http client
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpEntity httpEntity = null;
            HttpResponse httpResponse = null;

            // Checking http request method type
            if (method == POST) {
                HttpPost httpPost = new HttpPost(url);
                // adding post params
                if (params != null) {
                    httpPost.setEntity(new UrlEncodedFormEntity(params));
                }

                httpResponse = httpClient.execute(httpPost);

            } else if (method == GET) {
                // appending params to url
                if (params != null) {
                    String paramString = URLEncodedUtils
                            .format(params, "utf-8");
                    url += "?" + paramString;
                }
                HttpGet httpGet = new HttpGet(url);

                httpResponse = httpClient.execute(httpGet);

            }
            httpEntity = httpResponse.getEntity();
            response = EntityUtils.toString(httpEntity);
            Log.v("test", response);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return response;

    }

它应该给我所有旅游景点的地理位置等,如下结果:

{
  "result": [
    {
      "/location/location/geolocation": [{
        "latitude":  37.826944,
        "longitude": -122.4225
      }],
      "type": "/travel/tourist_attraction",
      "mid":  "/m/0h594",
      "name": "Alcatraz Island"
    },
    {
      "/location/location/geolocation": [{
        "latitude":  27.174167,
        "longitude": 78.041944
      }],
      "type": "/travel/tourist_attraction",
      "mid":  "/m/0l8cb",
      "name": "Taj Mahal"
    }]

但相反,它给了我一个页面中间的结果(https://www.freebase.com/m/010gxlnv)包含旅游景点的所有信息。

06-11 22:00:52.776: D/Response:(774):     {
06-11 22:00:52.776: D/Response:(774):       "mid": "/m/010gxlnv",
06-11 22:00:52.776: D/Response:(774):       "name": "Tourist Attraction LatLongs",
06-11 22:00:52.776: D/Response:(774):       "lang": "en",
06-11 22:00:52.776: D/Response:(774):       "score": 169.224823
06-11 22:00:52.776: D/Response:(774):     }
06-11 22:00:52.776: D/Response:(774):   ],
06-11 22:00:52.776: D/Response:(774):   "cost": 5,
06-11 22:00:52.776: D/Response:(774):   "hits": 1
06-11 22:00:52.776: D/Response:(774): }

你知道我的代码有什么问题吗?

1 个答案:

答案 0 :(得分:0)

这个问题已经解决了。我使用googleapis.com/freebase/v1/mqlread而不是googleapis.com/freebase/v1/search

相关问题