android - 在 android 中发送带有文本的图像时,twitter4j 达到最大长度

标签 android twitter

我使用 twitter4j 在 android 中发布包含图像和文本的推文。我的文本被截断为小于 140。但我想知道为什么服务器响应超过 140 个字符异常。
这是我的尝试:

 message = trimTweet(message); // guaranteed max length is less than 140
 StatusUpdate status = new StatusUpdate(message);

    if(bitmapUri != null){
    status.setMedia(new File(getRealPathFromURI(getApplicationContext(), bitmapUri)));
    }

  twitter.updateStatus(status);

服务器响应:

  10-23 19:18:00.842: E//NewsActivity.java:280(25288):  
  TwitterException{exceptionCode=[b2b52c28-11aaaacd], statusCode=403, 
  message=Status is over 140 characters., code=186, retryAfter=-1, 
  rateLimitStatus=null, version=3.0.4}
  10-23 19:18:00.842: E//NewsDetailActivity.java:280(25288):    at  twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:162)
 10-23 19:18:00.842: E//NewsDetailActivity.java:280(25288):     at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
 10-23 19:18:00.842: E//NewsDetailActivity.java:280(25288):     at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:98)

从调试中,我可以看到我的推文消息少于 140 个字符(有时是 138 或 139)。但是当我尝试只发送 108 或 110 个字符时,发送成功。然后我想知道 twitter4j 将我的图像添加到推文文本中。那正确吗?
如何发送只有 140 个字符的图片和文本?

最佳答案

我终于明白了我的问题。添加 URL 或图像时,Twitter 将字符数限制为 118 个。我认为这听起来很愚蠢。从这个链接:http://mediacause.org/10-nonprofit-twitter-tips-140-characters/

We all get tripped up by just how limiting 140 characters can be (it sounds like a lot until you start typing). Add in a link or a photo, and your character count for accompanying text is cut down to 118. Keep this in mind when crafting tweets and include text that gets straight to the point

更新:感谢@Aggressor,现在 Twitter 更新的限制链接取决于 t.co 包装的 URL。
https 窃取了 23 个字符(原来是 21 个),因此文本只有 117 个字符。
对于非 https 网址,您有 118 个字符(包装后的网址为 22)。

https:
enter image description here

HTTP:
enter image description here

关于android - 在 android 中发送带有文本的图像时,twitter4j 达到最大长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19536573/

相关文章:

javascript - 我如何在点击 Twitter 关注按钮时运行一些 javascript 代码,API

ruby-on-rails - 为什么 Twitter API 在生产中返回 400 错误?

python - Unicode解码错误: 'ascii' codec can't decode byte 0xe2 in position 139: ordinal not in range(128)

css - Twitter 徽章毁了我的页脚

android - 使用 Rx 去抖按钮点击

android - 膨胀类 android.support.v7.internal.widget.ActionBarView 时出错

android - 以编程方式将按钮添加到布局

php - Base64 编码和查看图像

ruby - 如何直接使用 oauth gem 从 Twitter 检索状态?

android - 在 Android 中设置 ListView Alert Dialog 的默认选中项