Inserting blog via Java API leads to "We're sorry, but you don't have permission to access this resource."

Peter Keller <[email protected]>
Newsgroups gmane.comp.web.blogger.api
Message-ID <[email protected]>
I am not able to insert a new post using the new v3 Java API. Any attempt 
lead to a 403 HTTP status code with the error message "We're sorry, but you 
don't have permission to access this resource."

Java Code:

InputStream credentialStream = 
RunClient.class.getResourceAsStream(CLIENT_SECRETS_JSON);
Collection<String> scopes = Collections.singleton(BloggerScopes.BLOGGER);

HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();

GoogleCredential credential = GoogleCredential
   .fromStream(credentialStream, httpTransport, jsonFactory)
   .createScoped(scopes);

Blogger blogger = new Blogger.Builder(httpTransport, jsonFactory, 
credential)
    .setApplicationName("myApp")
    .build();

Posts posts = blogger.posts();

Author author = new Post.Author();
author.setId("...");

Post post = new Post();
post.setContent("<h1>Hallo Post</h1>");
post.setAuthor(author);
post.setTitle("API Test Post");
       
Posts.Insert insert = posts.insert(BLOG_ID, post);
insert.setIsDraft(true);

Post insertedPost = insert.execute();  // <-<-<-<- Here it fails!!!!!



Invoking this code leads to following Java Stracktrace:

Exception in thread "main" 
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 
Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "We're sorry, but you don't have permission to access this 
resource.",
    "reason" : "forbidden"
  } ],
  "message" : "We're sorry, but you don't have permission to access this 
resource."
}
    at 
com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
    at 
com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
    at 
com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
    at 
com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
    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 ch.keller.blogger.RunClient.test1(RunClient.java:153)
    at ch.keller.blogger.RunClient.main(RunClient.java:80)


Please note: 

- I use the most recent Java Blogger API. Dependency from build.gradle 
configiration: 'com.google.apis:google-api-services-blogger:v3-rev49-1.21.0'

- CLIENT_SECRETS_JSON points to a JSON file containing all credentials 
created via the Google console https://console.developers.google.com 

- Inserting a new post via Google API explorer 
https://developers.google.com/apis-explorer/?hl=en_US#p/blogger/v3/blogger.pages.insert 
worked as expected. So, I conclude, that the Blogger settings are OK.

- Reading a post works fine. So I conclude, that the private_key in the CLIENT_SECRETS_JSON 
file is OK. Java Code:

    Get get = posts.get(BLOG_ID, POST_ID);
    Post post = get.execute();


Can someone please help me with this?

- Is the Java code as it must be? I didn't find a working example for the 
most recent API version I use...

- Do I need to change the Blogger settings (even if accessing the blog via 
Google API explorer worked nicely)?

- How to debug this?

- How to fix this?





-- 
You received this message because you are subscribed to the Google Groups "Blogger Developer Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/bloggerdev.
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.