Exemple #1
0
  public static void main(String[] args) {
    MongoService mongoService = new MongoService();
    MongoCollection<Document> collection = mongoService.database.getCollection("facebookPosts");

    OAuth2Client client = CommonOAuth2.getOAuth2Client("facebook");
    // String appAccessToken = client.getAppAccessToken();
    String accessToken =
        "CAACEdEose0cBAAg15ALJYKJLYkcE3VcqqR735CMZCSX5txnfyhZBgVDqErYc0LvagNA0zmAKDMWDoe4XqbdhpAKzjiI2A8xGxJAZBcKbNZBOLczm7vlMlqZCLn0hG5zfoQRDfRrkxnXhwiAZBdXXrv9Q2UfYxSDMmGeq8PwIKgEPaz6dXjnXIBxnpNaMOcchgZD";
    client.setProperty("access_token", accessToken);

    String api =
        new ApiBuilder("/v2.0/643588696/feed").limit(25).until(2014, 6, 1, 0, 0).toString();
    System.out.println(api);

    while (true) {
      HashMap<String, Object> response = process(collection, client, api);
      if (!response.containsKey("paging")) break;
      api = get(response, "paging.next");
      List<NameValuePair> list = URLEncodedUtils.parse(api, Charset.forName("UTF-8"));
      for (NameValuePair nameValuePair : list) {
        System.out.println(nameValuePair);
      }
    }

    // 643588696/feed?until=1401351351
  }
Exemple #2
0
 private static HashMap<String, Object> process(
     MongoCollection<Document> collection, OAuth2Client client, String api) {
   HashMap<String, Object> response = client.get(api);
   List<?> data = (List<?>) response.get("data");
   for (Object object : data) {
     BasicDBObject basicDBObject = new BasicDBObject((HashMap<?, ?>) object);
     basicDBObject.put("_id", basicDBObject.get("id"));
     Bson filter = new BasicDBObject("_id", basicDBObject.get("id"));
     Document replacement = new Document(basicDBObject);
     collection.findOneAndReplace(filter, replacement);
   }
   return response;
 }