Ejemplo n.º 1
0
  public static void searchPlaces(Instagram instagram, double latitude, double longitude)
      throws Exception {
    int[] distancia = {10, 15, 20, 25};

    MediaFeed feed = instagram.searchMedia(latitude, longitude, null, null, 5000);
    List<MediaFeedData> feeds = feed.getData();
    for (MediaFeedData data : feeds) {
      System.out.printf(
          "Instagram -- Nombre: %s, latitud: %f, longitud: %f\n",
          data.getLocation().getName(),
          data.getLocation().getLatitude(),
          data.getLocation().getLongitude());
      for (int i = 0; i < 4; i++) {
        System.out.println("CON DISTANCIA " + distancia[i]);
        System.out.println();

        ArrayList<Place> places =
            PlacesService.search(
                "",
                data.getLocation().getLatitude(),
                data.getLocation().getLongitude(),
                distancia[i]);
        for (Place place : places) {
          System.out.printf(
              "\tGoogle Places -- Nombre: %s, latitud: %f, longitud: %f, tipos: %s\n",
              place.name, place.latitude, place.longitude, place.types);
        }
        System.out.println();
      }
    }
  }
Ejemplo n.º 2
0
  // Usar timestamps para los parametros
  public static void searchMedia(
      Instagram instagram, long fechaInicio, long fechaFin, double latitude, double longitude)
      throws Exception {

    PrintWriter writer = new PrintWriter("output.txt", "UTF-8");
    writer.println("userId;userName;mediaId;tags;createdTime;locationName;latitude;longitude");

    while (fechaInicio < fechaFin) {
      Date minTimeStamp = new Date((long) fechaInicio * 1000);
      Date maxTimeStamp = new Date((long) (fechaInicio + 3600) * 1000);

      System.out.println(minTimeStamp.toString());
      MediaFeed feed = instagram.searchMedia(latitude, longitude, maxTimeStamp, minTimeStamp, 5000);
      List<MediaFeedData> feeds = feed.getData();

      for (MediaFeedData data : feeds) {
        String line = "";

        String userId = data.getUser().getId();
        String userName = data.getUser().getUserName();
        String mediaId = data.getUser().getId();
        String tags = data.getTags().toString();
        String createdTime = data.getCreatedTime();
        String locationName = data.getLocation().getName();
        String locationLatitude = String.valueOf(data.getLocation().getLatitude());
        String locationLongitude = String.valueOf(data.getLocation().getLongitude());

        line +=
            userId
                + ";"
                + userName
                + ";"
                + mediaId
                + ";"
                + tags
                + ";"
                + createdTime
                + ";"
                + locationName
                + ";"
                + locationLatitude
                + ";"
                + locationLongitude;
        writer.println(line);
      }

      fechaInicio += 3600;
    }

    writer.close();
  }