0

我有以下代码在 java 中输出我和我的用户 twitter 时间线消息。我按照本教程获取以下代码

http://namingexception.wordpress.com/2011/09/12/how-easy-to-make-your-own-twitter-client-using-java/

import java.io.IOException;
import java.util.List;

import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;

public class SimpleTweet {

List<Status> statuses;
private final static String CONSUMER_KEY = "XXXXXX";
private final static String CONSUMER_KEY_SECRET = "XXXXXXX-123";

public void start() throws TwitterException, IOException {

Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECRET);


String accessToken = getSavedAccessToken();
String accessTokenSecret = getSavedAccessTokenSecret();
AccessToken oathAccessToken = new AccessToken(accessToken,accessTokenSecret);

twitter.setOAuthAccessToken(oathAccessToken);

twitter.updateStatus("Hello world :).");    

statuses = twitter.getHomeTimeline();
for (Status each : statuses) {

    System.out.println("Sent by: @" + each.getUser().getScreenName()
        + " - " + each.getUser().getName() + "\n" + each.getText()
        + "\n");
}

  }// start method ends here


private String getSavedAccessTokenSecret() {

return "vxcvvxcvxcvx";
}

private String getSavedAccessToken() {

return "eweweqweqweqwe";
}

  public static void main(String[] args) throws Exception {
new SimpleTweet().start();
  }  
 }

我得到以下输出

Sent by: @tweetrr - rr
Hello to all :).

Sent by: @addthis - AddThis
Just in time for @wordcampnyc, we have updated the AddThis WordPress plugin! Check it:    
http://t.co/cgOgRwyl

现在我希望输出为 XML 格式。我想知道是否有 API 可以做到这一点。提前致谢

4

1 回答 1

1

您可以使用betwixtfrom apacheBitwix 示例),使用它可以轻松地将 bean 或 hashmap 转换为 XML 格式。因此,您创建使用、等UserStatusBean字段调用的 bean ,填充 bean 并使用.sentBystatusmessage[BeanWriter][2]

于 2012-06-12T01:15:16.527 回答