Search in sources :

Example 1 with ImageUpload

use of twitter4j.media.ImageUpload in project twitter4j by yusuke.

the class ImgLyImageUpload method main.

/**
     * Usage: java twitter4j.examples.media.ImgLyImageUpload [image file path] [message]
     *
     * @param args message
     */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.media.ImgLyImageUpload [image file path] [message]");
        System.exit(-1);
    }
    try {
        ImageUpload upload = new ImageUploadFactory().getInstance(MediaProvider.IMG_LY);
        String url;
        if (args.length >= 2) {
            url = upload.upload(new File(args[0]), args[1]);
        } else {
            url = upload.upload(new File(args[0]));
        }
        System.out.println("Successfully uploaded image to img.ly at " + url);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to upload the image: " + te.getMessage());
        System.exit(-1);
    }
}
Also used : ImageUploadFactory(twitter4j.media.ImageUploadFactory) ImageUpload(twitter4j.media.ImageUpload) File(java.io.File) TwitterException(twitter4j.TwitterException)

Example 2 with ImageUpload

use of twitter4j.media.ImageUpload in project twitter4j by yusuke.

the class TwippleImageUpload method main.

/**
     * Usage: java twitter4j.examples.media.TwippleImageUpload [image file path] [message]
     *
     * @param args message
     */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.media.TwippleImageUpload [image file path] [message]");
        System.exit(-1);
    }
    try {
        ImageUpload upload = new ImageUploadFactory().getInstance(MediaProvider.TWIPPLE);
        String url;
        if (args.length >= 2) {
            url = upload.upload(new File(args[0]), args[1]);
        } else {
            url = upload.upload(new File(args[0]));
        }
        System.out.println("Successfully uploaded image to Twipple at " + url);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to upload the image: " + te.getMessage());
        System.exit(-1);
    }
}
Also used : ImageUploadFactory(twitter4j.media.ImageUploadFactory) ImageUpload(twitter4j.media.ImageUpload) File(java.io.File) TwitterException(twitter4j.TwitterException)

Aggregations

File (java.io.File)2 TwitterException (twitter4j.TwitterException)2 ImageUpload (twitter4j.media.ImageUpload)2 ImageUploadFactory (twitter4j.media.ImageUploadFactory)2