Re: problem with blogger java v3 api authentication
"'Brett Morgan' via Blogger Developer Group" <[email protected]>
| Newsgroups | gmane.comp.web.blogger.api |
|---|---|
| Message-ID | <CAAFdGSetGppwoA8RjnnmgzWSrNmd-092zaCB-xwKP0aL0XMxaw@mail.gmail.com> |
We don't accept service account logins on Blogger, sorry. brett On Tue, Jun 2, 2015 at 4:12 PM Paul Foxson <[email protected]> wrote: > Hi > I'm trying run a sample post insert using Blogger JAVA v3 api and running > into issues. Please let me know what I'm missing or doing incorrectly or > my setup is incorrect. > Our applications runs periodically without any user interaction and > automatically post to our blog. Process runs on a stand alone machine > without any user interaction. It was working fine before gdata was > deprecated. > > I took the following steps: > 1. enabled Blogger API v3 in developer console. > 2. created a service account under credentials and downloaded .p12 file. > (I assume service accounts are supported since > google-api-services-blogger-v3-rev48-java-1.20.0 has calls > like setServiceAccountId, setServiceAccountScopes > and setServiceAccountPrivateKeyFromP12File). > 3. downloaded google-api-services-blogger-v3-rev48-java-1.20.0 > > Running code below and getting, this error: > 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 testAuth.main(testAuth.java:136) > > ------------------------------------------- > my code: > try { > HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); > JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); > > GoogleCredential credential = > new GoogleCredential.Builder() > > .setTransport(httpTransport) > > .setJsonFactory(jsonFactory) > > .setServiceAccountId("[email protected]") > > .setServiceAccountScopes(Collections.singleton(BloggerScopes.BLOGGER)) > > .setServiceAccountPrivateKeyFromP12File(new File("xxxxxxxxxxx.p12")) > > .build(); > > > Blogger blogger = new Blogger.Builder(httpTransport, jsonFactory, > credential) > .setApplicationName("My Project") > .build(); > > // Construct a post to insert > Post content = new Post(); > content.setTitle("A test post"); > content.setContent("With <code>HTML</code> content"); > > String TEST_BLOG_ID = "xxxxxxxxxxx9897"; > > Insert postsInsertAction = blogger.posts().insert(TEST_BLOG_ID, content); > > // Restrict the result content to just the data we need. > > postsInsertAction.setFields("author/displayName,content,published,title,url"); > > // This step sends the request to the server. > Post post = postsInsertAction.execute(); //fails here > > // Now we can navigate the response. > System.out.println("Title: " + post.getTitle()); > System.out.println("Author: " + post.getAuthor().getDisplayName()); > System.out.println("Published: " + post.getPublished()); > System.out.println("URL: " + post.getUrl()); > System.out.println("Content: " + post.getContent()); > > } catch (GeneralSecurityException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > -- > 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 http://groups.google.com/group/bloggerdev. > For more options, visit https://groups.google.com/d/optout. > -- 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 http://groups.google.com/group/bloggerdev. For more options, visit https://groups.google.com/d/optout.