Example usage for twitter4j StatusUpdate StatusUpdate

List of usage examples for twitter4j StatusUpdate StatusUpdate

Introduction

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

Prototype

public StatusUpdate(String status) 

Source Link

Usage

From source file:com.learnncode.demotwitterimagepost.HelperMethods.java

License:Apache License

public static void postToTwitterWithInputStream(Context context, final Activity callingActivity,
        final InputStream inputStream, final String message, final TwitterCallback postResponse) {
    if (!LoginActivity.isActive(context)) {
        postResponse.onFinsihed(false);//from   w  w w. j  ava 2  s .com
        return;
    }

    final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(context.getResources().getString(R.string.twitter_consumer_key));
    configurationBuilder
            .setOAuthConsumerSecret(context.getResources().getString(R.string.twitter_consumer_secret));
    configurationBuilder.setOAuthAccessToken(LoginActivity.getAccessToken(context));
    configurationBuilder.setOAuthAccessTokenSecret(LoginActivity.getAccessTokenSecret(context));
    final Configuration configuration = configurationBuilder.build();
    final Twitter twitter = new TwitterFactory(configuration).getInstance();

    new Thread(new Runnable() {

        private double x;

        @Override
        public void run() {
            boolean success = true;
            try {
                x = Math.random();
                if (inputStream != null) {
                    final StatusUpdate status = new StatusUpdate(message);
                    status.setMedia("GIF image", inputStream);
                    twitter.updateStatus(status);
                } else {
                    Log.d(TAG, "----- Invalid File ----------");
                    success = false;
                }
            } catch (final Exception e) {
                e.printStackTrace();
                success = false;
            }

            final boolean finalSuccess = success;

            callingActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    postResponse.onFinsihed(finalSuccess);
                }
            });

        }
    }).start();
}

From source file:com.learnncode.twitter.async.TweetActionAsync.java

License:Apache License

@Override
protected Void doInBackground(Void... arg0) {

    try {//from  ww  w.j av a  2 s . co  m
        if (mActionType == ActionType.favorite) {
            mStatusObject.setTweetStatusObject(
                    TwitterHelper.getTwitterInstance(mContext).createFavorite(mTweetId), mPosition,
                    mActionType);

        } else if (mActionType == ActionType.unfavorite) {
            mStatusObject.setTweetStatusObject(
                    TwitterHelper.getTwitterInstance(mContext).destroyFavorite(mTweetId), mPosition,
                    mActionType);

        } else if (mActionType == ActionType.retweet) {

            mStatusObject.setTweetStatusObject(
                    TwitterHelper.getTwitterInstance(mContext).retweetStatus(mTweetId), mPosition, mActionType);

        } else if (mActionType == ActionType.reply) {
            Twitter twitter = TwitterHelper.getTwitterInstance(mContext);
            StatusUpdate statusUpdate = new StatusUpdate(mReplyText);
            statusUpdate.inReplyToStatusId(mTweetId);
            mStatusObject.setTweetStatusObject(twitter.updateStatus(statusUpdate), mPosition, mActionType);

        } else if (mActionType == ActionType.tweet) {
            Twitter twitter = TwitterHelper.getTwitterInstance(mContext);
            StatusUpdate statusUpdate = new StatusUpdate(mReplyText);
            if (imageFile != null) {
                statusUpdate.setMedia(imageFile);
            }

            mStatusObject.setTweetStatusObject(twitter.updateStatus(statusUpdate), mPosition, mActionType);
        }

    } catch (Exception e) {
        mStatusObject.setTweetStatusObject(null, mPosition, mActionType);
    }
    return null;
}

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

License:Apache License

@Override
public FREObject call(FREContext context, FREObject[] args) {
    super.call(context, args);

    String text = (args[0] == null) ? null : FREObjectUtils.getString(args[0]);
    mCallbackID = FREObjectUtils.getInt(args[1]);
    long inReplyToStatusID = (args[2] == null) ? -1 : Long.valueOf(FREObjectUtils.getString(args[2]));
    final List<MediaSource> mediaSources = (args[3] == null) ? null
            : FREObjectUtils.getListOfMediaSource((FREArray) args[3]);

    final AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken());
    twitter.addListener(this);

    final StatusUpdate status = new StatusUpdate(text);
    if (inReplyToStatusID >= 0) {
        status.setInReplyToStatusId(inReplyToStatusID);
    }/*from  w  w w . j  av a2s .c o m*/
    /* If we have some media, system files must be created and uploaded to Twitter */
    if (mediaSources != null) {
        /* Save cache dir path before running the async task */
        AIR.setCacheDir(AIR.getContext().getActivity().getCacheDir().getAbsolutePath());
        /* Execute async task that creates files out of the given sources (URLs and Bitmaps) */
        createFilesFromSources(mediaSources, twitter, status);
        return null;
    }

    /* Posts status without media */
    twitter.updateStatus(status);

    return null;
}

From source file:com.michaelfitzmaurice.clocktwerk.TweetResponder.java

License:Apache License

public void respondToMentions(Collection<Status> mentions) {

    LOG.info("Responding to {} mentions on behalf of {}", mentions.size(), myScreenName);

    long latestMentionSeen = -1;
    for (Status mention : mentions) {
        String replyMessage = replyBody(myScreenName, mention, tweetDatabase.getNextTweet());
        StatusUpdate reply = new StatusUpdate(replyMessage);
        long mentionTweetId = mention.getId();
        reply.setInReplyToStatusId(mentionTweetId);
        LOG.debug("Replying to mention with ID {}", mentionTweetId);
        try {/*  w  w  w  .  j  av a  2  s  .  c o  m*/
            twitterClient.updateStatus(reply);
            LOG.debug("Replied to mention with ID {}", mentionTweetId);
        } catch (TwitterException e) {
            LOG.error("Failed to reply to Tweet", e);
        }
        // even if we failed to reply, record the mention as seen
        if (mentionTweetId > latestMentionSeen) {
            latestMentionSeen = mentionTweetId;
        }
    }
    LOG.info("Finished replying to new mentions");
    updateLastMentionSeen(latestMentionSeen);
}

From source file:com.mobilesolutionworks.android.twitter.test.MainActivity.java

License:Apache License

@Override
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.btn_open: {
        mTwitter.open(new StatusCallback());
        break;//from   w ww . j  a  v  a 2s  . co  m
    }

    case R.id.btn_validate: {
        mTwitter.validate(new StatusCallback());
        break;
    }

    case R.id.btn_close: {
        mTwitter.close();
        break;
    }

    case R.id.btn_request1: {
        EditText id = (EditText) findViewById(R.id.status_update);

        StatusUpdate request = new StatusUpdate(id.getText().toString());
        mTwitter.tweets(request, new WorksTwitter.ResponseCallback() {
            @Override
            public void onCancelled(Exception error) {

            }

            @Override
            public void onCompleted(Status status) {
                Toast.makeText(MainActivity.this, "test response = " + status, Toast.LENGTH_SHORT).show();
            }

        });
        break;
    }

    //            case R.id.btn_request2: {
    //                Request request = new Request(null, "/804889722866833/likes", null, HttpMethod.GET, null);
    //                mFacebook.readRequest(request, new WorksFacebook.ResponseCallback() {
    //                    @Override
    //                    public void onCancelled() {
    //
    //                    }
    //
    //                    @Override
    //                    public void onCompleted(Response response) {
    //                        Toast.makeText(FacebookTestActivity.this, "test response = " + response, Toast.LENGTH_SHORT).show();
    //                    }
    //                });
    //                break;
    //            }
    //
    //            case R.id.btn_request3: {
    //                mFacebook.requestMe(new WorksFacebook.ResponseCallback() {
    //                    @Override
    //                    public void onCancelled() {
    //
    //                    }
    //
    //
    //                    @Override
    //                    public void onCompleted(Response response) {
    //                        Toast.makeText(FacebookTestActivity.this, "test response = " + response, Toast.LENGTH_SHORT).show();
    //                    }
    //                });
    //                break;
    //            }
    }
}

From source file:com.mysportsshare.mysportscast.utils.HelperMethods.java

License:Apache License

public static void postToTwitterWithImage(Context context, final Activity callingActivity,
        final String imageUrl, final String message, final TwitterCallback postResponse) {
    SharedPreferences mSharedPref = context.getSharedPreferences("Android_Twitter_Preferences",
            Context.MODE_PRIVATE);
    if (mSharedPref.getString(Constants.KEY_TWITTER_ACCESS_TOKEN, null) == null) {
        postResponse.onFinsihed(false);/*from  w  w w.  j av a2s.co m*/
        return;
    }

    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(HomeActivity.CONSUMER_KEY);
    configurationBuilder.setOAuthConsumerSecret(HomeActivity.CONSUMER_SECRET);
    configurationBuilder.setOAuthAccessToken(HomeActivity.getAccessToken((context)));
    configurationBuilder.setOAuthAccessTokenSecret(HomeActivity.getAccessTokenSecret(context));
    Configuration configuration = configurationBuilder.build();
    final Twitter twitter = new TwitterFactory(configuration).getInstance();

    final File file = new File(imageUrl);

    new Thread(new Runnable() {

        @Override
        public void run() {
            boolean success = true;
            try {
                if (file.exists()) {
                    StatusUpdate status = new StatusUpdate(message);
                    status.setMedia(file);
                    twitter.updateStatus(status);
                } else {
                    Log.d(TAG, "----- Invalid File ----------");
                    success = false;
                }
            } catch (Exception e) {
                e.printStackTrace();
                success = false;
            }

            final boolean finalSuccess = success;

            callingActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    postResponse.onFinsihed(finalSuccess);
                }
            });

        }
    }).start();
}

From source file:com.narvis.frontend.twitter.output.Output.java

License:Open Source License

@Override
public void setOuput(MessageInOut m) {
    try {//from   ww w  .  j  a  v a 2 s.c  om
        for (String s : this.getTweetList(m)) {
            StatusUpdate status = new StatusUpdate(s);
            status.setInReplyToStatusId(((TwitterMessageInOut) m).getIdResponseTo());
            this.twitterLink.updateStatus(status);
        }
    } catch (TwitterException ex) {
        NarvisLogger.logException(ex);
    }
}

From source file:com.rhymestore.twitter.commands.ReplyCommand.java

License:Open Source License

@Override
public void execute() throws TwitterException {
    String rhyme = null;/*from   ww w .  j  a v  a 2s.c  om*/
    String targetUser = status.getUser().getScreenName();

    try {
        rhyme = rhymeStore.getRhyme(status.getText());

        if (rhyme == null) {
            // Try to rhyme with the user screen name
            if (wordParser.isWord(targetUser)) {
                LOGGER.info("Trying to rhyme with the screen name: {}", targetUser);
                rhyme = rhymeStore.getRhyme(targetUser);
            }
        }

        if (rhyme == null) {
            rhyme = wordParser.getDefaultRhyme();

            LOGGER.info("No rhyme found. Using default rhyme: {}", rhyme);
        }
    } catch (IOException ex) {
        LOGGER.error("An error occured while connecting to the rhyme store. Could not reply to {}", targetUser,
                ex);
    }

    try {
        String tweet = TwitterUtils.reply(targetUser, rhyme);

        LOGGER.info("Replying to {} with: {}", targetUser, tweet);

        // Reply to the user
        StatusUpdate newStatus = new StatusUpdate(tweet);
        newStatus.setInReplyToStatusId(status.getId());
        twitter.updateStatus(newStatus);
    } catch (TwitterException ex) {
        LOGGER.error("Could not send reply to tweet " + status.getId(), ex);
    }
}

From source file:com.soomla.profile.social.twitter.SoomlaTwitter.java

License:Apache License

/**
 * {@inheritDoc}//  w  w w  . ja  v a  2  s  .  co m
 */
@Override
public void uploadImage(String message, String filePath,
        final SocialCallbacks.SocialActionListener socialActionListener) {
    if (!isInitialized) {
        return;
    }

    SoomlaUtils.LogDebug(TAG, "uploadImage");

    RefProvider = getProvider();
    RefSocialActionListener = socialActionListener;

    preformingAction = ACTION_UPLOAD_IMAGE;

    try {
        StatusUpdate updateImage = new StatusUpdate(message);
        updateImage.media(new File(filePath));
        twitter.updateStatus(updateImage);
    } catch (Exception e) {
        failListener(ACTION_UPLOAD_IMAGE, e.getMessage());
    }
}

From source file:com.tweet.HelperMethods.java

License:Apache License

public static void postToTwitterWithImage(Context context, final Activity callingActivity, final String message,
        final TwitterCallback postResponse) {
    if (!LoginActivity.isActive(context)) {
        postResponse.onFinsihed(false);//from ww  w  . j a v a  2s  . co  m
        return;
    }

    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(context.getResources().getString(R.string.twitter_consumer_key));
    configurationBuilder
            .setOAuthConsumerSecret(context.getResources().getString(R.string.twitter_consumer_secret));
    configurationBuilder.setOAuthAccessToken(LoginActivity.getAccessToken((context)));
    configurationBuilder.setOAuthAccessTokenSecret(LoginActivity.getAccessTokenSecret(context));
    Configuration configuration = configurationBuilder.build();
    final Twitter twitter = new TwitterFactory(configuration).getInstance();

    //final File file = new File(imageUrl);

    new Thread(new Runnable() {

        @Override
        public void run() {
            boolean success = true;
            try {

                if (StaticData.graphFile.exists()) {
                    Calendar cal = Calendar.getInstance();

                    StatusUpdate status = new StatusUpdate(message + "\n@" + cal.getTime().toString());
                    status.setMedia(StaticData.graphFile);
                    twitter.updateStatus(status);
                } else {
                    Log.d(TAG, "----- Invalid File ----------");
                    success = false;
                }
            } catch (Exception e) {
                e.printStackTrace();
                success = false;
            }

            final boolean finalSuccess = success;

            callingActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    postResponse.onFinsihed(finalSuccess);
                }
            });

        }
    }).start();
}