blogger api blogger客户端 blogger开发
发贴的函数和上传图片的函数
// 返回post成功后的httpUrl
String createPost(String title, String content, String authorName,
boolean isDraft, String[] cats) throws ServiceException, IOException {
// Create the entry to insert
Entry myEntry = new Entry();
myEntry.setTitle(new PlainTextConstruct(title)); // 标题
myEntry.setContent(new PlainTextConstruct(content)); // 内容
Person author = new Person(authorName, null, username); // 发贴人
myEntry.getAuthors().add(author);
myEntry.setDraft(isDraft); // 是否保存到发贴箱
// 添加labels,分类
for(int c=0; cats != null && c<cats.length; c++) {
Category category = new Category();
category.setScheme(ATOM_NS);
category.setTerm(cats[c]);
myEntry.getCategories().add(category);
}
Entry e = bloggerService.insert(postUrl, myEntry);
//System.out.println(e.getHtmlLink().getHref());
return e.getHtmlLink().getHref(); // 返回成功后的http链接
}
// 返回上传达室上成功后的图片的httpUrl
GGImage createPhoto(File image, String albumId) throws IOException,
ServiceException {
if (picasaService == null) {
picasaLogin();
}
photoUrl = new URL(PICASA_API.concat(this.username).concat("/albumid/")
.concat(albumId).concat("?kind=photo"));
BaseEntry myPhoto = new PhotoEntry();
myPhoto.setTitle(new PlainTextConstruct(image.getName()));
((PhotoEntry) myPhoto).setDescription(new PlainTextConstruct(image.getName()));
((PhotoEntry) myPhoto).setClient(SOURCE);
((PhotoEntry) myPhoto).setTimestamp(new Date());
((PhotoEntry) myPhoto).setAlbumId(albumId);
MediaFileSource myMedia = new MediaFileSource(image, "image/gif");
myPhoto.setMediaSource(myMedia);
PhotoEntry returnedPhoto = (PhotoEntry) picasaService.insert(photoUrl,
myPhoto);
PhotoFeed gfeed = picasaService.getFeed(new URL(returnedPhoto
.getFeedLink().getHref()), PhotoFeed.class);
return new GGImage(gfeed.getIcon(), gfeed.getWidth().intValue(), gfeed.getHeight().intValue());
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
class GGImage {
String httpUrl; // 存放实际的http图片地址
int width;
int height;
public GGImage(String httpUrl, int width, int height) {
super();
this.httpUrl = httpUrl;
this.width = width;
this.height = height;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public String getHttpUrl() {
return httpUrl;
}
public void setHttpUrl(String httpUrl) {
this.httpUrl = httpUrl;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
}
相关文章:
Blogger Api 的简单应用(1)
Blogger Api 的简单应用(2)
Blogger Api 的简单应用(4)
测试我写的blogger客户端的发贴
Blogger客户端myblogger下载
Labels:
Trackback: http://cwq.iou1314.com/_a151
Trackback: http://cwq.iou1314.com/_a151




















