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.klinker.android.twitter.services.SecondMentionsRefreshService.java

License:Apache License

@Override
public void onHandleIntent(Intent intent) {
    sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    Context context = getApplicationContext();
    AppSettings settings = AppSettings.getInstance(context);

    // if they have mobile data on and don't want to sync over mobile data
    if (Utils.getConnectionStatus(context) && !settings.syncMobile) {
        return;/*from  w  ww.j a v  a  2s .co  m*/
    }

    boolean update = false;
    int numberNew = 0;

    try {
        Twitter twitter = Utils.getSecondTwitter(context);

        int currentAccount = sharedPrefs.getInt("current_account", 1);

        if (currentAccount == 1) {
            currentAccount = 2;
        } else {
            currentAccount = 1;
        }

        MentionsDataSource dataSource = MentionsDataSource.getInstance(context);

        long lastId = dataSource.getLastIds(currentAccount)[0];
        Paging paging;
        paging = new Paging(1, 200);
        if (lastId > 0) {
            paging.sinceId(lastId);
        }

        List<Status> statuses = twitter.getMentionsTimeline(paging);

        numberNew = MentionsDataSource.getInstance(context).insertTweets(statuses, currentAccount);

        if (numberNew > 0 && settings.notifications && settings.mentionsNot) {
            NotificationUtils.notifySecondMentions(context, currentAccount);
        }

    } catch (TwitterException e) {
        // Error in updating status
        Log.d("Twitter Update Error", e.getMessage());
    }
}

From source file:com.krossovochkin.kwitter.tasks.FavoriteAsyncTask.java

License:Apache License

@Override
protected Boolean doInBackground(Object... objects) {
    if (twitter != null) {
        try {/*from  w  w  w . ja v a 2 s.  c  o m*/
            twitter.createFavorite(tweetId);
            return true;
        } catch (TwitterException e) {
            Log.e(TAG, "Retweet failed: " + e.getMessage());
            return false;
        }
    } else {
        Log.e(TAG, "Retweet failed: twitter is null. Did you set it in a proper way?");
        return false;
    }
}

From source file:com.krossovochkin.kwitter.tasks.RetweetAsyncTask.java

License:Apache License

@Override
protected Boolean doInBackground(Object... objects) {
    if (twitter != null) {
        try {//from  ww  w. ja  v a 2  s  .  co  m
            twitter.retweetStatus(tweetId);
            return true;
        } catch (TwitterException e) {
            Log.e(TAG, "Retweet failed: " + e.getMessage());
            return false;
        }
    } else {
        Log.e(TAG, "Retweet failed: twitter is null. Did you set it in a proper way?");
        return false;
    }
}

From source file:com.krossovochkin.kwitter.tasks.SendReplyAsyncTask.java

License:Apache License

private boolean sendReply(final Twitter twitter, long tweetId, final String tweet) {
    try {/*from  ww w . j a  va  2  s  . c o m*/
        twitter.updateStatus(new StatusUpdate(tweet).inReplyToStatusId(tweetId));
        return true;
    } catch (TwitterException te) {
        Log.e(TAG, "Failed send tweet: " + te.getMessage());
        return false;
    }
}

From source file:com.krossovochkin.kwitter.tasks.SendTweetAsyncTask.java

License:Apache License

private boolean sendTweet(final Twitter twitter, final String tweet) {
    try {/*from w ww  .  ja v  a  2s.c  om*/
        twitter.updateStatus(tweet);
        return true;
    } catch (TwitterException te) {
        Log.e(TAG, "Failed send tweet: " + te.getMessage());
        return false;
    }
}

From source file:com.marklogic.tweetdeck.LoadRawJSON.java

License:Apache License

/**
 * Usage: java twitter4j.examples.json.LoadRawJSON
 *
 * @param args String[]//from  w  ww . ja  va 2  s.c  o m
 */
public static void main(String[] args) {
    try {
        File[] files = new File("statuses").listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.endsWith(".json");
            }
        });
        for (File file : files) {
            String rawJSON = readFirstLine(file);
            Status status = TwitterObjectFactory.createStatus(rawJSON);
            System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
        }
        System.exit(0);
    } catch (IOException ioe) {
        ioe.printStackTrace();
        System.out.println("Failed to store tweets: " + ioe.getMessage());
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get timeline: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:com.marklogic.tweetdeck.SaveRawJSON.java

License:Apache License

/**
 * Usage: java twitter4j.examples.json.SaveRawJSON
 *
 * @param args/*from   ww w. java 2  s.  c o  m*/
 *            String[]
 */
public static void main(String[] args) {
    Twitter twitter = new TwitterFactory().getInstance();
    System.out.println("Saving public timeline.");
    try {
        new File("statuses").mkdir();
        List<Status> statuses = twitter.getHomeTimeline();
        for (Status status : statuses) {
            String rawJSON = TwitterObjectFactory.getRawJSON(status);
            String fileName = "statuses/" + status.getId() + ".json";
            storeJSON(rawJSON, fileName);
            System.out.println(fileName + " - " + status.getText());
        }
        System.out.print("\ndone.");
        System.exit(0);
    } catch (IOException ioe) {
        ioe.printStackTrace();
        System.out.println("Failed to store tweets: " + ioe.getMessage());
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get timeline: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:com.marpies.ane.twitter.data.TwitterAPI.java

License:Apache License

public static void getAccessTokensForPIN(String PIN) {
    final AsyncTwitter twitter = getAsyncInstance();
    twitter.addListener(new TwitterAdapter() {
        @Override/*from ww  w.  j  av  a 2s.  c  o  m*/
        public void gotOAuthAccessToken(AccessToken token) {
            AIR.log("Retrieved access tokens");
            /* Store access tokens */
            TwitterAPI.storeAccessTokens(token);
            AIR.dispatchEvent(AIRTwitterEvent.LOGIN_SUCCESS);
        }

        @Override
        public void onException(TwitterException te, TwitterMethod method) {
            if (method == TwitterMethod.OAUTH_ACCESS_TOKEN) {
                AIR.dispatchEvent(AIRTwitterEvent.LOGIN_ERROR, StringUtils.removeLineBreaks(te.getMessage()));
            }
        }
    });
    twitter.getOAuthAccessTokenAsync(mRequestToken, PIN);
}

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

License:Apache License

@Override
public void onException(TwitterException te, TwitterMethod method) {
    if (method == TwitterMethod.DESTROY_STATUS) {
        AIR.log("Error destroying status: " + te.getMessage());
        AIR.dispatchEvent(AIRTwitterEvent.STATUS_QUERY_ERROR,
                StringUtils.getEventErrorJSON(mCallbackID, te.getMessage()));
    }/*from   w  w w  .  j  a v a2  s  .  com*/
}

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

License:Apache License

@Override
public void onException(TwitterException te, TwitterMethod method) {
    if (method == TwitterMethod.CREATE_FRIENDSHIP) {
        AIR.log("Error trying to follow user: " + te.getMessage());
        AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_ERROR,
                StringUtils.getEventErrorJSON(mCallbackID, te.getMessage()));
    }/*from ww  w .  j  av a  2 s  . c om*/
}