English 中文(简体)
Android image image 图像[复制]
原标题:Android twitter tweet with image [duplicate]
  • 时间:2012-05-17 11:44:20
  •  标签:
  • android
This question already has answers here:
Closed 11 years ago.

Possible Duplicate:
Can we post image on twitter using twitter API in Android?

我正在从事一项roid应用工作,我想敲响一个电文和照片。 我只能用手法敲响:

String token = prefs.getString(OAuth.OAUTH_TOKEN, "");
String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, "");

AccessToken a = new AccessToken(token, secret);
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(Constants.CONSUMER_KEY,
        Constants.CONSUMER_SECRET);
twitter.setOAuthAccessToken(a);
try {

**twitter.updateStatus("New tweet");**
        twitter.//Which property of twitter should I use to tweet an image and  //message
} catch (TwitterException e) {
    // TODO Auto-generated catch block
    Log.e("Errorssssssssssssss", e.toString());
}

How do I include an image as well?

最佳回答

。 http://www.londatiga.net/it/how-to-post-twitter-status- from-android/, 图书馆

public void uploadPic(File file, String message) throws Exception  {
    try{
    StatusUpdate status = new StatusUpdate(message);
    status.setMedia(file);
    mTwitter.updateStatus(status);}
    catch(TwitterException e){
        Log.d("TAG", "Pic Upload error" + e.getErrorMessage());
        throw e;
    }
}

在Twitter是“Twitter”类案件的情况下

确保你使用最新版本的tw4j-分jar档案。

问题回答

美国可以尝试Twitter4j图书馆的例子。 遵循法典将有助于u

public final class TwitpicImageUpload {
    /**
     * Usage: java twitter4j.examples.media.TwitpicImageUpload [API key] [message]
     *
     * @param args message
     */
    public static void main(String[] args) {
        if (args.length < 2) {
            System.out.println("Usage: java twitter4j.examples.media.TwitpicImageUpload [API key] [image file path] [message]");
            System.exit(-1);
        }
        try {
            Configuration conf = new ConfigurationBuilder().setMediaProviderAPIKey(args[0]).build();
            ImageUpload upload = new ImageUploadFactory(conf).getInstance(MediaProvider.TWITPIC);
            String url;
            if (args.length >= 3) {
                url = upload.upload(new File(args[1]), args[2]);
            } else {
                url = upload.upload(new File(args[1]));
            }
            System.out.println("Successfully uploaded image to Twitpic at " + url);
            System.exit(0);
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to upload the image: " + te.getMessage());
            System.exit(-1);
        }
    }
}

下载Twitter4j 图书馆寻找更多实例。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签