api , . .
private static GoogleCredential getCredentials(HttpTransport httpTransport, JacksonFactory jacksonFactory,
List<String> scopes) throws IOException, GeneralSecurityException {
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jacksonFactory,
CLIENT_ID, CLIENT_SECRET, scopes).setAccessType("online").setApprovalPrompt("auto").build();
String url = flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URI).build();
System.out.println("Please open the following URL in your " + "browser then type the authorization code:");
System.out.println(" " + url);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String code = br.readLine();
GoogleTokenResponse response = flow.newTokenRequest(code).setRedirectUri(REDIRECT_URI).execute();
System.out.println("Response : " + response.toPrettyString());
GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
.setJsonFactory(jacksonFactory).setServiceAccountId("xyz@gmail.com")
.setServiceAccountPrivateKeyFromP12File(new File("resources\\xyz.p12"))
.setServiceAccountScopes(Collections.singleton(BloggerScopes.BLOGGER)).build();
credential.setAccessToken(response.getAccessToken());
return credential;
}
public static Blogger getBlog() throws IOException, GeneralSecurityException, AuthenticationException {
if (blog == null) {
if (httpTransport == null)
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
if (jacksonFactory == null)
jacksonFactory = JacksonFactory.getDefaultInstance();
blog = new Blogger.Builder(httpTransport, jacksonFactory,
getCredentials(httpTransport, jacksonFactory, Arrays.asList(BloggerScopes.BLOGGER)))
.setApplicationName("Blogger").build();
}
return blog;
}
public static void udpatePost(String title, String content) throws IOException, AuthenticationException, GeneralSecurityException{
Post post = new Post();
post.setTitle(title);
post.setContent(content);
Update updateAction = getBlog().posts().update(BLOG_ID, POST_ID, post);
updateAction.setFields("author/displayName,content,published,title,url");
post = updateAction.execute();
System.out.println("Published: " + post.getPublished());
}
JAR API v3: http://developers.google.com/blogger/docs/3.0/api-lib/java