Example usage for twitter4j TwitterException getMessage

List of usage examples for twitter4j TwitterException getMessage

Introduction

In this page you can find the example usage for twitter4j TwitterException getMessage.

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:com.marpies.ane.twitter.functions.RetweetStatusFunction.java

License:Apache License

@Override
public void onException(TwitterException te, TwitterMethod method) {
    if (method == TwitterMethod.RETWEET_STATUS) {
        AIR.log("Error retweeting status: " + te.getMessage());
        AIR.dispatchEvent(AIRTwitterEvent.STATUS_QUERY_ERROR,
                StringUtils.getEventErrorJSON(mCallbackID, te.getMessage()));
    }//from   w  w  w . j a va  2 s .co m
}

From source file:com.marpies.ane.twitter.functions.SendDirectMessageFunction.java

License:Apache License

@Override
public void onException(TwitterException te, TwitterMethod method) {
    if (method == TwitterMethod.SEND_DIRECT_MESSAGE) {
        AIR.log("Error trying to send DM: " + te.getMessage());
        AIR.dispatchEvent(AIRTwitterEvent.DIRECT_MESSAGE_QUERY_ERROR,
                StringUtils.getEventErrorJSON(mCallbackID, te.getMessage()));
    }/*from  www . jav  a2s .  c o m*/
}

From source file:com.marpies.ane.twitter.functions.UndoLikeStatusFunction.java

License:Apache License

@Override
public void onException(TwitterException te, TwitterMethod method) {
    if (method == TwitterMethod.DESTROY_FAVORITE) {
        AIR.log("Error removing liked status: " + te.getMessage());
        AIR.dispatchEvent(AIRTwitterEvent.STATUS_QUERY_ERROR,
                StringUtils.getEventErrorJSON(mCallbackID, te.getMessage()));
    }/*  w  w  w . j a v  a  2 s.co m*/
}

From source file:com.marpies.ane.twitter.functions.UnfollowUserFunction.java

License:Apache License

@Override
public void onException(TwitterException te, TwitterMethod method) {
    if (method == TwitterMethod.DESTROY_FRIENDSHIP) {
        AIR.log("Error trying to unfollow user: " + te.getMessage());
        AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_ERROR,
                StringUtils.getEventErrorJSON(mCallbackID, te.getMessage()));
    }//w  w w  .  jav  a  2s.com
}

From source file:com.marpies.ane.twitter.functions.UpdateStatusFunction.java

License:Apache License

private void uploadMedia(final AsyncTwitter twitter, final StatusUpdate status, final List<File> mediaList,
        final Integer callbackID) {
    /* Run the upload in separate thread */
    new Thread(new Runnable() {
        @Override/*from   w ww .  ja v  a2 s. co  m*/
        public void run() {
            final long[] mediaIDs = new long[mediaList.size()];
            try {
                /* Synchronous twitter4j must be used in order to upload the media */
                Twitter syncTwitter = TwitterAPI.getInstance(TwitterAPI.getAccessToken());
                for (int i = 0; i < mediaIDs.length; i++) {
                    File mediaFile = mediaList.get(i);
                    AIR.log("Uploading media " + mediaFile.getAbsolutePath());
                    UploadedMedia uploadedMedia = syncTwitter.uploadMedia(mediaFile);
                    mediaIDs[i] = uploadedMedia.getMediaId();
                }
                // todo: remove cached media files
                status.setMediaIds(mediaIDs);
                /* Update status only if there is no exception during media upload */
                twitter.updateStatus(status);
            } catch (TwitterException e) {
                AIR.log("Error uploading media " + e.getMessage());
                /* Failed to upload media, let's not update status without the media */
                AIR.dispatchEvent(AIRTwitterEvent.STATUS_QUERY_ERROR, StringUtils.getEventErrorJSON(callbackID,
                        StringUtils.removeLineBreaks(e.getMessage())));
            }
        }
    }).start();
}

From source file:com.marpies.ane.twitter.functions.UpdateStatusFunction.java

License:Apache License

@Override
public void onException(TwitterException te, TwitterMethod method) {
    if (method == TwitterMethod.UPDATE_STATUS) {
        AIR.log("Error updating status " + te.getMessage());
        AIR.dispatchEvent(AIRTwitterEvent.STATUS_QUERY_ERROR,
                StringUtils.getEventErrorJSON(mCallbackID, te.getMessage()));
    }/*from   ww  w  .  j av  a  2s . c  om*/
}

From source file:com.marpies.ane.twitter.LoginActivity.java

License:Apache License

/**
 *
 *
 * Private API//ww w . ja v a 2s . c o m
 *
 *
 */

private TwitterAdapter getOAuthRequestTokenListener(final boolean forceLogin) {
    return new TwitterAdapter() {
        @Override
        public void gotOAuthRequestToken(RequestToken token) {
            TwitterAPI.setRequestToken(token);
            StringBuilder urlBuilder = new StringBuilder(token.getAuthenticationURL());
            if (forceLogin) {
                urlBuilder.append("&force_login=true");
            }
            /* Launch browser */
            LoginActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(urlBuilder.toString())));
        }

        @Override
        public void onException(TwitterException te, TwitterMethod method) {
            if (method == TwitterMethod.OAUTH_REQUEST_TOKEN) {
                AIR.log("Request token exception " + te.getMessage());
                AIR.dispatchEvent(AIRTwitterEvent.LOGIN_ERROR, StringUtils.removeLineBreaks(te.getMessage()));
            }
            finish();
        }
    };
}

From source file:com.metadot.book.connectr.server.servlets.LoginTwitterServlet.java

License:Apache License

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

    Twitter twitter = new TwitterFactory().getInstance();
    // get auth info from system properties
    String key = AuthenticationProvider.getProp("twitter-consumer-key");
    String secret = AuthenticationProvider.getProp("twitter-consumer-secret");

    if (key == null || secret == null) {
        response.setContentType("text/html");
        response.getWriter().print(AppLib.INFONOTFOUND);
        return;/*from www.  ja va 2s  .co m*/
    }

    try {
        twitter.setOAuthConsumer(key, secret);
        String callbackURL = buildCallBackURL(request, AuthenticationProvider.TWITTER);
        RequestToken token = twitter.getOAuthRequestToken(callbackURL);
        request.getSession().setAttribute("requestToken", token);
        String loginURL = token.getAuthenticationURL() + "&force_login=true";
        log.info("Redirecting to: " + loginURL);
        response.sendRedirect(loginURL);

    } catch (TwitterException e) {
        response.setContentType("text/html");
        response.getWriter().print("<p>" + e.getMessage() + "</p>");
        response.getWriter().print(AppLib.INFONOTFOUND);
        return;
        // e.printStackTrace();
    }

}

From source file:com.michaelfitzmaurice.clocktwerk.apps.TwitterPropertiesTool.java

License:Apache License

/**
 * Usage: java  twitter4j.examples.oauth.GetAccessToken [consumer key] [consumer secret]
 *
 * @param args/*from   w  ww  . ja  v a  2 s .c om*/
 */
public static void main(String[] args) {

    File file = new File(TWITTER4J_PROPERTIES_FILE_NAME);
    Properties prop = new Properties();
    InputStream is = null;

    try {
        if (file.exists()) {
            System.out.println("Using existing twitter4j.properties file: " + file.getAbsolutePath());
            is = new FileInputStream(file);
            prop.load(is);
        }

        if (args.length < 2) {
            verifyOAuthProperties(prop);
        } else {
            createSkeletonPropertiesFile(args[0], args[1], prop);
        }
    } catch (IOException ioe) {
        printStackTraceAndExitSystem(ioe, null);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ignore) {
            }
        }
    }

    try {
        Twitter twitter = new TwitterFactory().getInstance();
        RequestToken requestToken = twitter.getOAuthRequestToken();
        System.out.println("Got request token.");
        System.out.println("Request token: " + requestToken.getToken());
        System.out.println("Request token secret: " + requestToken.getTokenSecret());
        AccessToken accessToken = null;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (null == accessToken) {
            System.out.println(
                    "Open the following URL in an authenticated " + "Twitter session as the target user:");
            System.out.println(requestToken.getAuthorizationURL());
            try {
                Desktop.getDesktop().browse(new URI(requestToken.getAuthorizationURL()));
            } catch (IOException ignore) {
            } catch (URISyntaxException e) {
                throw new AssertionError(e);
            } catch (UnsupportedOperationException ignore) {
            }

            System.out.print("Enter the authorization PIN and hit enter:");
            String pin = br.readLine();
            try {
                if (pin.length() > 0) {
                    accessToken = twitter.getOAuthAccessToken(requestToken, pin);
                } else {
                    accessToken = twitter.getOAuthAccessToken(requestToken);
                }
            } catch (TwitterException te) {
                if (401 == te.getStatusCode()) {
                    System.out.println("Unable to get the access token.");
                } else {
                    te.printStackTrace();
                }
            }
        }
        System.out.println("Got access token.");
        System.out.println("Access token: " + accessToken.getToken());
        System.out.println("Access token secret: " + accessToken.getTokenSecret());

        OutputStream os = null;
        try {
            prop.setProperty(OAUTH_ACCESS_TOKEN_PROPERTY, accessToken.getToken());
            prop.setProperty(OAUTH_ACCESS_TOKEN_SECRET_PROPERTY, accessToken.getTokenSecret());
            os = new FileOutputStream(file);
            prop.store(os, TWITTER4J_PROPERTIES_FILE_NAME);
        } catch (IOException ioe) {
            printStackTraceAndExitSystem(ioe, null);
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (IOException ignore) {
                }
            }
        }
        System.out.println("Successfully stored access token to " + file.getAbsolutePath() + ".");
        System.exit(0);
    } catch (TwitterException te) {
        printStackTraceAndExitSystem(te, "Failed to get accessToken: " + te.getMessage());
    } catch (IOException ioe) {
        printStackTraceAndExitSystem(ioe, "Failed to read the system input.");
    }
}

From source file:com.mycompany.dovetune.SearchTwitter.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// w  w w .j a  v a 2s .  c  o m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, TwitterException {

    //            HttpSession session = request.getSession(false);

    //            if(session != null){

    Twitter twitter = (Twitter) request.getSession().getAttribute("twitter");

    if (twitter != null) {
        String soundcloudUrl = request.getParameter("soundcloudUrl");
        String songName = request.getParameter("songName");
        out.println(twitter.toString());

        int i = songName.indexOf("- ");
        String song = songName.substring(i + 2);
        try {
            Query query = new Query("(#" + song + ") OR ( " + songName + ") OR (#DoveTune)");

            QueryResult result = twitter.search(query);

            List<Status> tweets = result.getTweets();
            //                String list = "<ulid='tweetList'>";
            String list = "";
            for (Status tweet : tweets) {
                list += "<li><img class='profileImg' src='" + tweet.getUser().getProfileImageURL()
                        + "' title='Profile Image' alt='Profile Image'><strong>" + tweet.getUser().getName()
                        + " @" + tweet.getUser().getScreenName() + "</strong> - " + tweet.getText() + "</li>";
            }

            list = list.replace("#" + song, "<strong class='hashtags'>#" + song + "</strong>");
            list = list.replace("#DoveTune", "<strong class='hashtags'>#DoveTune</strong>");
            list = list.replace("#SoundCloud", "<strong class='hashtags'>#SoundCloud</strong>");
            String songL = song;
            songL = songL.toLowerCase();
            list = list.replace("#" + songL, "<strong class='hashtags'>#" + songL + "</strong>");
            if (list.equals("")) {
                list = "<li>There are no tweets to display. Tweet your own!</li>";
            }

            request.setAttribute("soundcloudUrl", soundcloudUrl);
            request.setAttribute("songName", songName);
            request.setAttribute("song", songName);
            request.setAttribute("list", list);

        } catch (TwitterException te) {
            te.printStackTrace();
            out.println("Failed to search tweets: " + te.getMessage());
            System.exit(-1);
        }
    } else {
        String list = "<ul><li>In order to view tweets, please sign in to <a href=\"SignIn\" title=\"Sign in to Twitter\"><strong class=\"notSignedIn\">Twitter</strong></a></li></ul>";
        request.setAttribute("list", list);
    }

    request.getRequestDispatcher("details.jsp").forward(request, response);

}