[英]foursquare API and java
我打算开发一个利用Web服务(特别是Foursquare API和Google Map Web Service)的非常简单的Java应用程序(不是移动应用程序,而是桌面应用程序)。 我计划获取用户地址,然后使用Google Map将地址转换为纬度和经度,然后将此结果提供给foursquare API方法Venue方法(附近和搜索)以获取附近场所的结果并将其显示给用户。 问题是:
对不起所有菜鸟问题。
更新:
我尚未在FourSquare注册。 试试看,让我知道它是否适合您:
package foursquare;
import java.io.*;
import java.net.Authenticator;
import java.net.URL;
/**
* FourSquareDemo
* User: Michael
* Date: 10/19/10
* Time: 7:53 PM
*/
public class FourSquareDemo
{
private static final int DEFAULT_CAPACITY = 4096;
private static final String DEFAULT_URL = "http://api.foursquare.com/v1/";
private static final String DEFAULT_EMAIL = "you@gmail.com";
private static final String DEFAULT_PASSWORD = "password";
public static void main(String[] args)
{
long startTime = System.currentTimeMillis();
long endTime = 0L;
try
{
String downloadSite = ((args.length > 0) ? args[0] : DEFAULT_URL);
URL url = new URL(downloadSite + "history");
Authenticator.setDefault(new BasicAuthenticator(DEFAULT_EMAIL, DEFAULT_PASSWORD));
String contents = readFromUrl(url);
PrintStream ps = ((args.length > 1) ? new PrintStream(new FileOutputStream(new File(args[1]))) : System.out);
printToStream(ps, contents);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
endTime = System.currentTimeMillis();
System.out.println("wall time: " + (endTime - startTime) + " ms");
}
}
private static void printToStream(PrintStream ps, String contents) throws IOException
{
ps.println(contents.toString());
ps.close();
}
private static String readFromUrl(URL url) throws IOException
{
StringBuilder contents = new StringBuilder(DEFAULT_CAPACITY);
BufferedReader br = null;
try
{
InputStream is = url.openConnection().getInputStream();
br = new BufferedReader(new InputStreamReader(is));
String line;
String newline = System.getProperty("line.separator");
while ((line = br.readLine()) != null)
{
contents.append(line).append(newline);
}
}
finally
{
try
{
if (br != null)
{
br.close();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
return contents.toString();
}
}
Foursqare API使用简单的HTTP get方法(又名RESTful Web服务)。 有许多方法可以用Java调用RESTful Web服务,请参阅:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.