新浪微博 官网sdk .
在调用 public Status UploadStatus(String status, ImageItem item) 这个接口发布带图片的微博时,出现如下异常:
weibo4j2.model.WeiboException: 400:The request was invalid. An accompanying error message will explain why. This is the status code will be returned during rate limiting. error:does multipart has image? error_code:20007/2/statuses/upload.json at weibo4j2.http.HttpClient.multPartURL(HttpClient.java:334) at weibo4j2.Timeline.UploadStatus(Timeline.java:765) at com.chineseall.util.SnsPostThread.run(SnsPostThread.java:51) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) Caused by: weibo4j2.model.WeiboException: 400:The request was invalid. An accompanying error message will explain why. This is the status code will be returned during rate limiting. error:does multipart has image? error_code:20007/2/statuses/upload.json at weibo4j2.http.HttpClient.httpRequest(HttpClient.java:413) at weibo4j2.http.HttpClient.httpRequest(HttpClient.java:371) at weibo4j2.http.HttpClient.multPartURL(HttpClient.java:331) ... 5 more
解决:
参数里的 ImageItem 这个对象,在 new 的时候,如果使用了 new ImageItem(name, content) 这个构造方法的话,
则 第一个参数 必须是 pic
new ImageItem("pic",byteArrayOutStream.toByteArray());