0

我正在尝试使用其 Java API v2 创建一个 Foursquare 应用程序,但我找不到任何用于签入过程的示例源代码。我不需要完整的源代码(身份验证、场地搜索等),我只需要签入部分。

有人可以帮助我吗?

4

1 回答 1

2
import java.net.*;
import java.io.*;

class HelloCheckin {
public static void main(String[] args) {

try {
    // Construct data
    String data = URLEncoder.encode("ll", "UTF-8") + "=" + URLEncoder.encode("53.576317,0.113386", "UTF-8");
    data += "&" + URLEncoder.encode("venueId", "UTF-8") + "=" + URLEncoder.encode("4e144a2cc65bedaeefbb824a", "UTF-8");
    data += "&" + URLEncoder.encode("oauth_token", "UTF-8") + "=" + URLEncoder.encode("YOUR_OAUTHTOKEN", "UTF-8");

    // Send data
    URL url = new URL("https://api.foursquare.com/v2/checkins/add");
    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);
    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
    wr.write(data);
    wr.flush();

    // Get the response
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));

    String line;
    while ((line = rd.readLine()) != null) {
        // Process line...
    }
    wr.close();
    rd.close();
} catch (Exception e) {
}

} }

这段代码的主体来自Simple Java Post

于 2011-09-08T21:40:26.017 回答