hi I am trying to make a Twitter bot that produces titles of blog
entries. Since I am not good at Java, the problem might be in
understanding of Java itself.
I keep getting an error message "java.lang.NoClassDefFoundError: com/
google/gdata/util/ServiceException", and I have searched the web for
information. But all I found was the lack of libs, such as mail.jar ,
google.collect...jar . I tried to include all possible libs, but no
change at all.
Could anyone help me out?
//---- servlet that produces
tweets-------------------------------------------------
public class Twitter_botServlet extends HttpServlet {
private static final Logger log =
Logger.getLogger(Twitter_botServlet.class.getName());
private String botname = "new_public_line";
private String cachedtoken = "access_token";
private String cachedsecret = "access_secret";
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.setCharacterEncoding("utf-8");
resp.getWriter().println("Hello, world");
log.info("info test");
PersistenceManager pm = PMF.get().getPersistenceManager();
Cache cache = null;
try {
CacheFactory cacheFactory =
CacheManager.getInstance().getCacheFactory();
cache =
cacheFactory.createCache(Collections.emptyMap());
} catch (CacheException e) {
log.info(e.getMessage());
}
if((String)cache.get(cachedtoken) == null ||
(String)cache.get(cachedsecret) == null){
Query query = pm.newQuery(Token.class);
List<Token> tokens = (List<Token>)query.execute();
for(Token token:tokens){
if(token !=null &&
token.getBotName().equals(botname)){
cache.put(cachedtoken,
token.getAccessToken());
cache.put(cachedsecret,
token.getAccessSecret());
}
}
pm.close();
}
GenerateInputs(cache);
}
private void GenerateInputs(Cache cache) {
Twitter twitter = new
TwitterFactory().getOAuthAuthorizedInstance(new
AccessToken((String)cache.get(cachedtoken),
(String)cache.get(cachedsecret)));
String title = new
GetBlogEntriesServlet().ReturnInfo();
try {
twitter.updateStatus(title);
} catch (TwitterException e) {
System.out.println(e.getMessage());
}
}
}
//--- tweet servlet ends here -----
//--- servlet that gets a blog title-----
public class GetBlogEntriesServlet extends HttpServlet {
public String ReturnInfo() {
String blogId = "xxxxxxxxxxxx";
String title = null;
try {
GoogleService myService = new GoogleService("blogger",
"twitter_bot");
title = printAllPosts(myService, blogId);
} catch (ServiceException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}
return title;
}
private static String printAllPosts(GoogleService myService,
String blogId) throws ServiceException, IOException {
final URL feedUrl = new URL("http://www.blogger.com/feeds/" +
blogId
+ "/posts/default");
Feed resultFeed = myService.getFeed(feedUrl, Feed.class);
//define array that contains entry titles
String[] ArrayTitle;
ArrayTitle = new String[resultFeed.getEntries().size()];
System.out.println(resultFeed.getTitle().getPlainText());
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
Entry entry = resultFeed.getEntries().get(i);
ArrayTitle[i] = entry.getTitle().getPlainText();
}
//get one of blog titles using a random number
Random rnd = new Random();
int ran = rnd.nextInt(resultFeed.getEntries().size());
return ArrayTitle[ran];
}
}
//------ code ends
here------------------------------------------------------
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.