Example usage for twitter4j Twitter updateProfileImage

List of usage examples for twitter4j Twitter updateProfileImage

Introduction

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

Prototype

User updateProfileImage(File image) throws TwitterException;

Source Link

Document

Updates the authenticating user's profile image.

Usage

From source file:de.vanita5.twittnuker.util.TwitterWrapper.java

License:Open Source License

public static SingleResponse<ParcelableUser> updateProfileImage(final Context context, final long account_id,
        final Uri image_uri, final boolean delete_image) {
    final Twitter twitter = getTwitterInstance(context, account_id, false);
    if (twitter != null && image_uri != null && "file".equals(image_uri.getScheme())) {
        try {/*from www  . ja  v  a 2s .  c  om*/
            final User user = twitter.updateProfileImage(new File(image_uri.getPath()));
            // Wait for 5 seconds, see
            // https://dev.twitter.com/docs/api/1.1/post/account/update_profile_image
            Thread.sleep(5000L);
            return new SingleResponse<ParcelableUser>(new ParcelableUser(user, account_id), null);
        } catch (final TwitterException e) {
            return new SingleResponse<ParcelableUser>(null, e);
        } catch (final InterruptedException e) {
            return new SingleResponse<ParcelableUser>(null, e);
        }
    }
    return SingleResponse.getInstance();
}

From source file:org.getlantern.firetweet.util.TwitterWrapper.java

License:Open Source License

public static User updateProfileImage(final Context context, final Twitter twitter, final Uri imageUri,
        final boolean deleteImage) throws FileNotFoundException, TwitterException {
    InputStream is;//  w  w  w.j a v  a 2  s . c o m
    try {
        is = context.getContentResolver().openInputStream(imageUri);
        return twitter.updateProfileImage(is);
    } finally {
        if (deleteImage && "file".equals(imageUri.getScheme())) {
            final File file = new File(imageUri.getPath());
            if (!file.delete()) {
                Log.w(LOGTAG, String.format("Unable to delete %s", file));
            }
        }
    }
}

From source file:twitter4j.examples.account.UpdateProfileImage.java

License:Apache License

/**
 * Usage: java twitter4j.examples.account.UpdateProfileImage [image file path]
 *
 * @param args message//w w  w . j av  a 2 s .co m
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.account.UpdateProfileImage [image file path]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        twitter.updateProfileImage(new File(args[0]));
        System.out.println("Successfully updated profile image.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to update profile image: " + te.getMessage());
        System.exit(-1);
    }
}