【问题标题】:Android twitter4j upload imageAndroid twitter4j 上传图片
【发布时间】:2012-09-30 12:04:19
【问题描述】:

我有一个安卓应用程序,通过它我可以成功更新推特状态。我正在使用它来共享指向显示图像的网页的链接。我认为像 instagram 一样,将图像的缩小预览与推文一起进行会很好。如何将这张图片与我的推文一起上传?

【问题讨论】:

标签: android twitter4j multipartform-data


【解决方案1】:

我有时也有同样的要求,最后提供了这个功能,也许对你也有帮助。

/**
 * To upload a picture with some piece of text.
 * 
 * 
 * @param file The file which we want to share with our tweet
 * @param message Message to display with picture
 * @param twitter Instance of authorized Twitter class
 * @throws Exception exception if any
 */

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

注意:要使用这个,请确保你有最新的 jar 文件,我为此使用了 twitter4j-core-2.2.5.jar

【讨论】:

  • 不错!非常感谢。工作完美! :)
  • 按照您的建议将我的 twitter jar 从 2.i.i 替换为 2.2.5 后,我收到了新错误:AndroidRuntime(7452): java.lang.IllegalArgumentException: Invalid access token format。以前我可以发推文,但我只是在尝试上传图片。
  • 请问什么是 Twitter twitter
  • Twitter 是一个从 Twitter4j 库中使用的对象
  • 如果我想分享一个链接呢?
猜你喜欢
  • 2015-03-28
  • 2012-06-11
  • 2012-03-07
  • 2012-01-25
  • 2012-04-03
  • 2014-04-27
  • 2011-12-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多