private static void testWriteNoteEntry(DoubanService myService) { NoteEntry noteEntry; try { String content = "立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春"; noteEntry = myService.createNote( new PlainTextConstruct("立春"), new PlainTextConstruct(content), "public", "yes"); printNoteEntry(noteEntry); String content2 = "立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋立秋"; myService.updateNote( noteEntry, new PlainTextConstruct("立秋"), new PlainTextConstruct(content2), "public", "no"); myService.deleteNote(noteEntry); } catch (IOException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } }
private static void testWriteCollectionEntry(DoubanService myService) { try { CollectionEntry ce; Rating rating = new Rating(); rating.setValue(4); ArrayList<Tag> tags = new ArrayList<Tag>(2); Tag t1 = new Tag(); t1.setName("顾长卫"); Tag t2 = new Tag(); t2.setName("李樯"); tags.add(t1); tags.add(t2); String movieId = "3036997"; // 立春(And the Spring Comes) SubjectEntry se = myService.getMovie(movieId); ce = myService.createCollection(new Status("watched"), se, tags, rating); printCollectionEntry(ce); myService.deleteCollection(ce); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } }
private static void testReviewEntry(DoubanService myService) { ReviewEntry reviewEntry; try { String reviewId = "1138468"; reviewEntry = myService.getReview(reviewId); printReviewEntry(reviewEntry); String userId = "1026712"; ReviewFeed reviewFeed = myService.getUserReviews(userId); for (ReviewEntry sf : reviewFeed.getEntries()) { printReviewEntry(sf); } String movieId = "1424406"; // start-index=2&max-results=2 reviewFeed = myService.getMovieReviews(movieId, 2, 2, "score"); for (ReviewEntry sf : reviewFeed.getEntries()) { printReviewEntry(sf); } reviewFeed = myService.getMovieReviews(movieId, 2, 2, "time"); for (ReviewEntry sf : reviewFeed.getEntries()) { printReviewEntry(sf); } } catch (IOException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } }
private static void testTagFeed(DoubanService myService) { try { String userId = "sakinijino"; // cat=movie&start-index=2&max-results=3 TagFeed tf = myService.getUserTags(userId, "movie", 2, 3); for (TagEntry te : tf.getEntries()) { printTagEntry(te); } String movieId = "1424406"; // start-index=1&max-results=10 tf = myService.getMovieTags(movieId, 1, 10); for (TagEntry te : tf.getEntries()) { printTagEntry(te); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } }
public static void main(String[] args) { String apiKey = CommonData.apikey; String secret = CommonData.secret; DoubanService myService = new DoubanService("treenewbee", apiKey, secret); System.out.println( "please paste the url in your webbrowser, complete the authorization then come back:"); System.out.println(myService.getAuthorizationUrl(null)); byte buffer[] = new byte[1]; try { System.in.read(buffer); } catch (IOException e) { e.printStackTrace(); } myService.getAccessToken(); // myService.setAccessToken("", ""); System.out.println("User related test:"); testUserEntry(myService); testUserFriends(myService); /*System.out.println("Subject related test:"); testSubjectEntry(myService);*/ System.out.println("Review related test:"); testReviewEntry(myService); testWriteReviewEntry(myService); /* System.out.println("Collection related test:"); testCollectionEntry(myService); testCollectionFeed(myService); testWriteCollectionEntry(myService); System.out.println("Note related test:"); testNoteEntry(myService); testWriteNoteEntry(myService); System.out.println("Tag feedest:"); testTagFeed(myService); System.out.println("Miniblog related test:"); testMiniblogEntry(myService);*/ }
private static void testNoteEntry(DoubanService myService) { NoteEntry noteEntry; NoteFeed noteFeed; try { String noteId = "17730279"; noteEntry = myService.getNote(noteId); printNoteEntry(noteEntry); noteFeed = myService.getUserNotes("aka", 2, 2); for (NoteEntry ne : noteFeed.getEntries()) { printNoteEntry(ne); } } catch (IOException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } }
private static void testMiniblogEntry(DoubanService myService) { String userId = "sakinijino"; MiniblogFeed mf; try { mf = myService.getUserMiniblogs(userId, 1, 2); for (MiniblogEntry me : mf.getEntries()) { printMiniblogEntry(me); } mf = myService.getContactsMiniblogs("apitest", 1, 2); for (MiniblogEntry me : mf.getEntries()) { printMiniblogEntry(me); } myService.createSaying(new PlainTextConstruct("Hello Douban API java client!")); } catch (IOException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } }
private static void testSubjectEntry(DoubanService myService) { SubjectEntry subjectEntry; try { String bookId = "2023013"; subjectEntry = myService.getBook(bookId); printSubjectEntry(subjectEntry); // tag=cowboy&start-index=1&max-results=2 // q=null SubjectFeed subjectFeed = myService.findMovie(null, "cowboy", 1, 2); for (SubjectEntry sf : subjectFeed.getEntries()) { printSubjectEntry(sf); } } catch (IOException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } }
private static void testUserEntry(DoubanService myService) { UserEntry userEntry; try { String userId = "ahbei"; userEntry = myService.getUser(userId); printUserEntry(userEntry); // printUserEntry(myService.getAuthorizedUser()); // q=douban&start-index=10&max-results=1 UserFeed userFeed = myService.findUser("douban", 1, 1); for (UserEntry ue : userFeed.getEntries()) { printUserEntry(ue); } } catch (IOException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } }
@Override protected void onResume() { super.onResume(); // 取得SharedPreferences保存的数据 SharedPreferences sharedata = getSharedPreferences("data", 0); String accessToken = sharedata.getString("accessToken", null); String tokenSecret = sharedata.getString("tokenSecret", null); String uid = sharedata.getString("uid", null); doubanService.setAccessToken(accessToken, tokenSecret); NetUtil.setUid(uid); }
private static void testUserFriends(DoubanService myService) { try { UserFeed uf = myService.getUserFriends("subdragon", 1, 2); for (UserEntry ue : uf.getEntries()) { printUserEntry(ue); } } catch (IOException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } }
private static void testWriteReviewEntry(DoubanService myService) { ReviewEntry reviewEntry; try { String movieId = "3036997"; // 立春(And the Spring Comes) SubjectEntry se = myService.getMovie(movieId); Rating rate = new Rating(); rate.setValue(4); String content = "立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春立春"; reviewEntry = myService.createReview( se, new PlainTextConstruct("立春"), new PlainTextConstruct(content), rate); printReviewEntry(reviewEntry); myService.deleteReview(reviewEntry); } catch (IOException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } }
private static void testCollectionEntry(DoubanService myService) { try { String cid = "1123456"; CollectionEntry ce = myService.getCollection(cid); printCollectionEntry(ce); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } }
private static void testCollectionFeed(DoubanService myService) { try { String userId = "sakinijino"; // cat=movie&start-index=1&max-results=2&tag=TimBurton // status=null CollectionFeed cf = myService.getUserCollections(userId, "movie", "TimBurton", null, 1, 2); for (CollectionEntry ce : cf.getEntries()) { printCollectionEntry(ce); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } }