Example #1
0
 /**
  * Retrieve a specific post from a blog by sending a GET request to the posts resource URI
  *
  * @param blogId The blog id
  * @param postId The post id
  * @return the post in the blog
  */
 private Post retrievePostById(String blogId, String postId) {
   Post bloggerPost = null;
   try {
     String json =
         doGetRestBloggerApi(
             "https://www.googleapis.com/blogger/v3/blogs/" + blogId + "/posts/" + postId,
             bloggerAccessToken);
     Gson gson = new Gson();
     JsonElement element = gson.fromJson(json, JsonElement.class);
     JsonObject jobj = element.getAsJsonObject();
     String kind = jobj.get("kind").getAsString();
     String id = jobj.get("id").getAsString();
     String published = jobj.get("published").getAsString();
     String updated = jobj.get("updated").getAsString();
     String url = jobj.get("url").getAsString();
     String selfLink = jobj.get("selfLink").getAsString();
     String title = jobj.get("title").getAsString();
     String content = jobj.get("content").getAsString();
     bloggerPost = new Post(id, url, selfLink, title, content);
     bloggerPost.setKind(kind);
     bloggerPost.setPublished(published);
     bloggerPost.setUpdated(updated);
   } catch (Exception e) {
     return null;
   }
   return bloggerPost;
 }