0

我尝试连接到 Foursquare 网络服务以解析查找某些位置,但我的程序无法连接到 Foursquare 网络服务。这是我的代码:

公共类 GetLocation {

public static void main (String [] args ) throws IOException
{

    //Set up for output locations in a .txt file
    String fileNameOut = "locations.txt" ; 
    FileOutputStream fos = new FileOutputStream( fileNameOut );
    PrintStream ps = new PrintStream(fos);
    String client_id = "Y2LZCJTR4LJBXZOXAB3F22VOLAV3GXRS5TSXRXXXXXXXXXXX";
    String client_secret = "PJY2QM4CLZITAUMGOQCM2QYTOKATTCH3VXXXXXXXXXXX";

    double latitude = 33.823712;
    double longtitude = -117.958931;
    String restaurantName = "Cafe Casse Croute";
    String V = "20121205";

            String API_URL = "http://api.foursquare.com/v2/venues/search?ll=";
        String queryStatement = latitude+","+longtitude+"&match="+restaurantName;

           try {
                 String url = (API_URL+queryStatement+"&client_id="+client_id+"&client_secret="+client_secret + "&v="+V);


           URL url = new URL(sURL);

           URLConnection httpc = url.openConnection();
       //HttpURLConnection httpc = (HttpURLConnection) url.openConnection();    
           httpc.setDoInput(true);
           httpc.connect();

        BufferedReader in = new BufferedReader(new InputStreamReader(httpc.getInputStream()));

        String inputLine = "";
        String content="";
        while ((inputLine = in.readLine()) != null){
             content=content+inputLine;

        }
        in.close();

        return content;
    } catch (Exception e) {
        return ("Exception: " + e.getMessage());
    }

}

}

我也尝试使用 URLConnection httpc = (URLConnection) url.openConnection(); 但它没有连接到 FoureSquare 服务。

还有其他方法可以连接到 FoureSquare 服务吗?

4

0 回答 0