0

I'm trying to create a Foursquare application using its Java API v2 but I couldn't find any sample source code for the checkin process. I don't need to full source code (authentication, venue search, etc), I just need to checkin part.

Can somebody help me?

vegidio
  • 822
  • 2
  • 11
  • 32
  • i think that you can find one here http://stackoverflow.com/questions/3972477/foursquare-api-and-java – phoet Aug 25 '11 at 12:03
  • Thanks but this example uses the version 1 of the API and it's no longer supported by Foursquare. – vegidio Aug 25 '11 at 12:37
  • link guessing :) https://github.com/wareninja/foursquare-wrapper-for-android/blob/master/src/com/wareninja/android/commonutils/foursquareV2/FoursquareHttpApiV2.java – phoet Aug 25 '11 at 12:57

1 Answers1

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) {
}

} }

The body of this code came from Simple Java Post

Aerilys
  • 1,628
  • 1
  • 16
  • 22
Bassdread
  • 350
  • 2
  • 6
  • but its generating exception :-12-29 12:21:07.425: java.io.FileNotFoundException: https://api.foursquare.com/v2/checkins/add/ org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnec tionImpl.getInputStream(HttpURLConnectionImpl.java:1162) org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:253) – Pushpendra Kuntal Dec 29 '11 at 07:11