Example usage for twitter4j TwitterException toString

List of usage examples for twitter4j TwitterException toString

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:net.lacolaco.smileessence.twitter.task.UnfavoriteTask.java

License:Open Source License

@Override
protected twitter4j.Status doInBackground(Void... params) {
    try {/*from   w w w  .  jav  a2  s.co  m*/
        return twitter.favorites().destroyFavorite(statusID);
    } catch (TwitterException e) {
        e.printStackTrace();
        Logger.error(e.toString());
        return null;
    }
}

From source file:net.lacolaco.smileessence.twitter.task.UnfollowTask.java

License:Open Source License

@Override
protected User doInBackground(Void... params) {
    try {//from w  ww .  j a v a  2s .  c  o m
        return twitter.friendsFollowers().destroyFriendship(userID);
    } catch (TwitterException e) {
        e.printStackTrace();
        Logger.error(e.toString());
        return null;
    }
}

From source file:net.lacolaco.smileessence.twitter.task.UserListStatusesTask.java

License:Open Source License

@Override
protected twitter4j.Status[] doInBackground(Void... params) {
    ResponseList<twitter4j.Status> responseList;
    try {/*ww  w . ja v  a  2  s . c o  m*/
        String[] strings = listFullName.split("/");
        responseList = twitter.list().getUserListStatuses(strings[0], strings[1], paging);
    } catch (TwitterException e) {
        e.printStackTrace();
        Logger.error(e.toString());
        return new twitter4j.Status[0];
    }
    return responseList.toArray(new twitter4j.Status[responseList.size()]);
}

From source file:net.lacolaco.smileessence.twitter.task.UserTimelineTask.java

License:Open Source License

@Override
protected twitter4j.Status[] doInBackground(Void... params) {
    ResponseList<twitter4j.Status> responseList;
    try {//from   w  ww. j  a  va  2 s . c  om
        if (paging == null) {
            responseList = twitter.timelines().getUserTimeline(userID);
        } else {
            responseList = twitter.timelines().getUserTimeline(userID, paging);
        }
    } catch (TwitterException e) {
        e.printStackTrace();
        Logger.error(e.toString());
        return new twitter4j.Status[0];
    }
    return responseList.toArray(new twitter4j.Status[responseList.size()]);
}

From source file:nl.isaac.dotcms.twitter.util.TwitterUtil.java

License:Creative Commons License

/**
 * Get tweets from current User/*from  w  ww. j ava  2 s .c  o m*/
 * @param count
 * @return
 */
public List<CustomStatus> getUserTimeline(int count) {
    List<CustomStatus> statuses = new ArrayList<CustomStatus>();

    try {
        statuses = formatStatus(twitter.getUserTimeline(new Paging(1, count)));
    } catch (TwitterException e) {
        throw new RuntimeException(e.toString(), e);
    }
    return statuses;
}

From source file:nl.isaac.dotcms.twitter.util.TwitterUtil.java

License:Creative Commons License

/**
 * Get tweets for given screenname User/*from  www .  java 2 s  .  c  o m*/
 * @param count
 * @return
 */
public List<CustomStatus> getUserTimeline(String screenname, int count) {
    List<CustomStatus> statuses = new ArrayList<CustomStatus>();

    try {
        statuses = formatStatus(twitter.getUserTimeline(screenname, new Paging(1, count)));
    } catch (TwitterException e) {
        throw new RuntimeException(e.toString(), e);
    }
    return statuses;
}

From source file:nl.isaac.dotcms.twitter.util.TwitterUtil.java

License:Creative Commons License

public List<CustomStatus> search(String from) {
    try {//from   ww  w  . j a  va 2  s  . c o m
        Query query = new Query(from);
        QueryResult result;

        result = twitter.search(query);
        List<CustomStatus> tweets = formatStatus(result.getTweets());
        return tweets;

    } catch (TwitterException te) {
        throw new RuntimeException(te.toString(), te);
    }
}

From source file:org.apache.nutch.protocol.http.api.HttpBase.java

License:Apache License

public ProtocolOutput getProtocolOutput(String url, WebPage page) {

    try {/*from   ww  w. j  ava2 s  .c  o  m*/
        host = null;
        response = null;
        contents = null;
        u = null;
        code = 0;
        c = null;

        if (url.indexOf("graph.facebook") > 0) {
            url = handleFaceBookContent(url);
        } else if (url.indexOf("api.twitter.com") > 0) {
            try {
                handleTwitterContent(url);
            } catch (TwitterException e) {
                e.printStackTrace(System.err);
                code = e.getStatusCode();
                c = null;
            }
        } else {
            handleSiteContent(url, page);
        }
        // request

        if (code == 200) { // got a good response
            return new ProtocolOutput(c); // return it

        } else if (code == 410) { // page is gone
            return new ProtocolOutput(c,
                    ProtocolStatusUtils.makeStatus(ProtocolStatusCodes.GONE, "Http: " + code + " url=" + url));
        } else if (code >= 300 && code < 400) { // handle redirect
            String location = response.getHeader("Location");
            // some broken servers, such as MS IIS, use lowercase header
            // name...
            if (location == null)
                location = response.getHeader("location");
            if (location == null)
                location = "";
            u = new URL(u, location);
            int protocolStatusCode;
            switch (code) {
            case 300: // multiple choices, preferred value in Location
                protocolStatusCode = ProtocolStatusCodes.MOVED;
                break;
            case 301: // moved permanently
            case 305: // use proxy (Location is URL of proxy)
                protocolStatusCode = ProtocolStatusCodes.MOVED;
                break;
            case 302: // found (temporarily moved)
            case 303: // see other (redirect after POST)
            case 307: // temporary redirect
                protocolStatusCode = ProtocolStatusUtils.TEMP_MOVED;
                break;
            case 304: // not modified
                protocolStatusCode = ProtocolStatusUtils.NOTMODIFIED;
                break;
            default:
                protocolStatusCode = ProtocolStatusUtils.MOVED;
            }
            // handle this in the higher layer.
            return new ProtocolOutput(c, ProtocolStatusUtils.makeStatus(protocolStatusCode, u));
        } else if (code == 400) { // bad request, mark as GONE
            if (logger.isTraceEnabled()) {
                logger.trace("400 Bad request: " + u);
            }
            return new ProtocolOutput(c, ProtocolStatusUtils.makeStatus(ProtocolStatusCodes.GONE, u));
        } else if (code == 401) { // requires authorization, but no valid
            // auth provided.
            if (logger.isTraceEnabled()) {
                logger.trace("401 Authentication Required");
            }
            return new ProtocolOutput(c, ProtocolStatusUtils.makeStatus(ProtocolStatusCodes.ACCESS_DENIED,
                    "Authentication required: " + url));
        } else if (code == 404) {
            return new ProtocolOutput(c, ProtocolStatusUtils.makeStatus(ProtocolStatusCodes.NOTFOUND, u));
        } else if (code == 410) { // permanently GONE
            return new ProtocolOutput(c, ProtocolStatusUtils.makeStatus(ProtocolStatusCodes.GONE, u));
        } else {
            return new ProtocolOutput(c, ProtocolStatusUtils.makeStatus(ProtocolStatusCodes.EXCEPTION,
                    "Http code=" + code + ", url=" + u));
        }
    } catch (Throwable e) {
        e.printStackTrace(LogUtil.getErrorStream(logger));
        return new ProtocolOutput(null,
                ProtocolStatusUtils.makeStatus(ProtocolStatusCodes.EXCEPTION, e.toString()));
    }
}

From source file:org.botlibre.sense.twitter.Twitter.java

License:Open Source License

public void log(TwitterException exception) {
    log(new TextStream(exception.toString()).nextLine(), Bot.WARNING);
}

From source file:org.kawalpemilukada.login.callbackTwit.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* www .j  av  a  2  s  .co 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 {
    Twitter twitter = (Twitter) request.getSession().getAttribute("twitter");
    RequestToken requestToken = (RequestToken) request.getSession().getAttribute("requestToken");
    String verifier = request.getParameter("oauth_verifier");
    String rurl = request.getParameter("rurl");
    try {
        twitter.getOAuthAccessToken(requestToken, verifier);
        request.getSession().removeAttribute("requestToken");
    } catch (TwitterException e) {
    }
    request.getSession().setAttribute("twitter", twitter);
    String errorMsg = "Data Anda belum terverifikasi.";
    Dashboard dashboard = CommonServices.getDashboard(CommonServices.setParentId("2015", "0"));
    Dashboard dashboard2014 = CommonServices.getDashboard(CommonServices.setParentId("2014", "0"));
    request.getSession().removeAttribute("tahun");
    UserData user = null;
    try {
        User u = twitter.showUser(twitter.getId());
        user = ofy().load().type(UserData.class).id("twit" + CommonServices.getVal(twitter.getId())).now();
        if (user == null) {
            user = new UserData("twit" + CommonServices.getVal(twitter.getId()));
            user.imgurl = u.getBiggerProfileImageURLHttps().replace("http://", "https://");
            user.nama = CommonServices.getVal(u.getName());
            user.link = "https://twitter.com/" + CommonServices.getVal(twitter.getScreenName());
            user.email = "";
            user.type = "twit";
            user.userlevel = 100;
            user.terverifikasi = "Y";
            ofy().save().entity(user).now();
            dashboard.users = CommonServices.getuserSize() + "";
            ofy().save().entity(dashboard).now();
            dashboard2014.users = dashboard.users + "";
            ofy().save().entity(dashboard2014).now();
        } else {
            user.lastlogin = CommonServices.JakartaTime();
            user.type = "twit";
            user.imgurl = u.getBiggerProfileImageURL().replace("http://", "https://");
            if (user.type.equalsIgnoreCase("twit")
                    && user.nama.equalsIgnoreCase(CommonServices.getVal(u.getName()))) {
                if (user.terverifikasi.equalsIgnoreCase("Y")) {
                    errorMsg = "";
                }
            } else {
                user.nama = CommonServices.getVal(u.getName());
                user.terverifikasi = "N";
            }
            ofy().save().entity(user).now();
        }
        Gson gson = new Gson();
        request.getSession().setAttribute("UserData", JSONValue.parse(gson.toJson(user)));
    } catch (Exception e) {
        errorMsg = "callbackTwit [processRequest] ==> " + e.toString();
    }
    response.setContentType("text/html;charset=UTF-8");
    Gson gson = new Gson();
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Kawal Pemilu Kepala Daerah</title>");
        out.println("<script src=\"/bower_components/jquery/dist/jquery.min.js\"></script>");
        out.println("<script src=\"/dist/js/vendor.js\"></script>");
        out.println("</head>");
        out.println("<body>Sedang Login...");
        out.println("<script>");
        out.println("if (!jQuery.browser.mobile) {");
        out.println("try{window.opener.inviteCallback(" + gson.toJson(user) + "," + gson.toJson(dashboard)
                + ",'" + errorMsg + "');}catch(e){window.location='/'}");
        out.println("self.close();");
        out.println("}else{window.location='/#" + rurl + "'}");
        out.println("</script>");
        out.println("</body>");
        out.println("</html>");
    }

}