如何使用JRI从Twitter中提取推文?

时间:2015-04-02 17:21:29

标签: java twitter sentiment-analysis jri

在Java中使用twitter4j.jar进行身份验证后,有人能告诉我如何连接到Twitter并提取推文吗?以下代码与Twitter进行身份验证有关,但我遇到了这个例外:

  

线程“main”中的异常java.lang.NoSuchMethodError:com.google.appengine.api.urlfetch.FetchOptions.setDeadline(Ljava / lang / Double;)Lcom / google / appengine / api / urlfetch / FetchOptions;

以下是我使用Twitter进行身份验证的代码:

public void authenticateTwitter() throws TwitterException, IOException
{        
        // The factory instance is re-useable and thread safe.
    Twitter twitter = TwitterFactory.getSingleton();
    twitter.setOAuthConsumer("AiDGpUznKUeaPmyJuLXM5g7lB", "pQVzheejaAWeOlGbmucIkpXxkneaTQ9jOE3IVn2D0MmnmRfa45");
    RequestToken requestToken = twitter.getOAuthRequestToken();
    AccessToken accessToken = null;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    while (null == accessToken) {
      System.out.println("Open the following URL and grant access to your account:");
      System.out.println(requestToken.getAuthorizationURL());
      System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:");
      String pin = br.readLine();
      try{
         if(pin.length() > 0){
           accessToken = twitter.getOAuthAccessToken(requestToken, pin);
         }else{
           accessToken = twitter.getOAuthAccessToken();
         }
      } catch (TwitterException te) {
        if(401 == te.getStatusCode()){
          System.out.println("Unable to get the access token.");
        }else{
          te.printStackTrace();
        }
      }
    }
    //persist to the accessToken for future reference.
    storeAccessToken((int)twitter.verifyCredentials().getId() , accessToken);
    Status status = twitter.updateStatus("Hello friends");
    System.out.println("Successfully updated the status to [" + status.getText() + "].");
    System.exit(0);

    }

0 个答案:

没有答案