title: Blogger API Sample Code
body: <p>So this is my first question on StackOverflow, so please let me know if there's something I've neglected to include!</p>
  
  <p>I'm trying to get Blog post data from public Blogger blogs for some language analysis research that I'm doing. Although the java API seems pretty straight-forward, I've found that Google's code sample at <a href="https://developers.google.com/blogger/docs/3.0/reference/posts/list#examples" rel="nofollow noreferrer">https://developers.google.com/blogger/docs/3.0/reference/posts/list#examples</a> does not work, as there are many dependencies missing, ranging from LocalServerReceiver() to a whole host of dependencies needed for OAuthorization. The API explorer works just fine, but obviously, I need something for my own code.</p>
  
  <p>I also tried utilizing code fragments from other StackOverflow questions that I saw were similar to mine, and am still facing dependency issues.</p>
  
  <p>Here's a list of some of the questions I've looked at, which have not solved my issue due to some sort of code deprecation:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/21002827/google-oauth2-api-client-is-not-working-properly">Google oauth2 api client is not working properly</a>  </p></li>
  <li><p><a href="https://stackoverflow.com/questions/17261806/why-does-java-not-allow-me-to-use-oauth2native-methods-here">Why does Java not allow me to use OAuth2Native methods here?</a></p></li>
  <li><a href="https://stackoverflow.com/questions/35369919/authenticate-own-google-account-for-blogger-api-with-java">Authenticate own Google account for Blogger API with Java</a></li>
  </ul>
  
  <p>I've used the OAuthPlayground to get an authorization code, and have been trying to replicate some of the functionality of iamkhova's solution in <a href="https://stackoverflow.com/questions/20462705/proper-form-of-api-request-to-blogger-using-java-app-engine-error-401">Proper Form of API request to Blogger using Java/App Engine -error 401</a>.  Note that I'm not actually trying to write anything to any of the blogs I'm accessing. I just want to be able to get the post data for analysis.</p>
  
  <p>Currently I've just altered iamkhova's solution by taking out the logger, and adding a getPosts() function that duplicates what I need from Google's sample code.</p>
  
  <pre><code>   public class BlogHandler
  {
    static final String API_KEY = {My API Key};
    public Blogger blogger = null;
    public Blog blog;
    public java.util.List&lt;Post&gt; posts;
  
    public BlogHandler() {}
  
    public void executeGetBlogByUrl (String url) throws IOException {
       GetByUrl request = blogger.blogs().getByUrl( url );
       this.blog = request.setKey(API_KEY).execute();
  
     }
    public void getPosts() throws IOException
    {
        List postsListAction = blogger.posts().list(this.blog.getId());
  
      // Restrict the result content to just the data we need.
      postsListAction.setFields("items(author/displayName,content,published,title,url),nextPageToken");
  
      // This step sends the request to the server.
      PostList posts = postsListAction.execute();
  
      // Now we can navigate the response.
      int postCount = 0;
      int pageCount = 0;
      while (posts.getItems() != null &amp;&amp; !posts.getItems().isEmpty()) {
              for (Post post : posts.getItems()) {
                      System.out.println("Post #"+ ++postCount);
                      System.out.println("\tTitle: "+post.getTitle());
                      System.out.println("\tAuthor: "+post.getAuthor().getDisplayName());
                      System.out.println("\tPublished: "+post.getPublished());
                      System.out.println("\tURL: "+post.getUrl());
                      System.out.println("\tContent: "+post.getContent());
              }
  
              // Pagination logic
              String pageToken = posts.getNextPageToken();
              if (pageToken == null || ++pageCount &gt;= 5) {
                      break;
              }
              System.out.println("-- Next page of posts");
              postsListAction.setPageToken(pageToken);
              posts = postsListAction.execute();
      }
  
    }
  
     public void setupService () throws IOException {
  
      AppIdentityCredential credential = null;
      credential  = new AppIdentityCredential(Arrays.asList(BloggerScopes.BLOGGER)); // Add your scopes here
      this.blogger = new Blogger.Builder(new UrlFetchTransport(), new JacksonFactory(), credential).setApplicationName("chsBlogResearch").build();
     }
  
  }
  </code></pre>
  
  <p>Currently, I'm having the following error:</p>
  
  <pre><code>Exception in thread "main" com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'memcache' or call 'Get()' was not found.
      at com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:173)
      at com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:171)
      at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:89)
      at com.google.appengine.api.memcache.MemcacheServiceImpl.quietGet(MemcacheServiceImpl.java:26)
      at com.google.appengine.api.memcache.MemcacheServiceImpl.get(MemcacheServiceImpl.java:49)
      at com.google.appengine.api.appidentity.AppIdentityServiceImpl.getAccessToken(AppIdentityServiceImpl.java:286)
      at com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential.intercept(AppIdentityCredential.java:98)
      at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
      at BloggerData.BlogHandler.executeGetBlogByUrl(BlogHandler.java:29)
  </code></pre>
  
  <p>Clicking on the code lines for both the errors in MemcacheServiceImpl and AppIdentityServiceImpl tell me that there are no lines of code at that point. I'm using Maven within Eclipse for dependencies.</p>
  
  <p>The only thing I'm not really sure about in this code is the idea of scopes, but I don't think that that should be causing my errors. </p>
  
  <p>I would appreciate any ideas on this, as getting this post data has been way more time-consuming than I thought it would be!</p>
  
  <p>Update: <a href="https://stackoverflow.com/questions/2299673/getting-strange-exception-trying-to-implement-asynchronous-http-in-google-app-en">getting strange exception trying to implement asynchronous http in google app engine for java</a> provided a little more insight on the error above. Apparently this ApiProxy jar cannot be called through a console app.</p>