java - android 新手 - 如何使用 SocialAuthAdapter 类中找到的 'uploadImage' 方法

标签 java android twitter twitter-oauth twitter4j

我正在尝试将图像上传到 Twitter。 SocialAuthAdapter class包含一个应该执行此操作的“uploadImage”方法。

这是我的代码:

public void post_image(){ 
File imgFile = new  File("/storage/sdcard0/pic_app/ubgthyghu.com2013923.png");
bitmap2 = decodeFile(imgFile); //this just brings back a resized bitmap, it works.. i  tested it
try {
Log.d(tag,"********************* picture is going to be updated...");
int returnvalue  = adapter.uploadImage("fred", "ubgthyghu.com2013923.png", bitmap2, 3);
Log.d(tag,"here is the return value:  " + returnvalue );
} catch (Exception e) {Log.d(tag,"u got an error haus");  e.printStackTrace();}
}//post_image

但是我收到以下消息:

09-27 07:39:16.280: D/ShareButtonActivity(11622): ********************* picture is going to be updated...
09-27 07:39:16.400: D/dalvikvm(11622): GC_CONCURRENT freed 424K, 10% free 12775K/14151K, paused 11ms+1ms, total 19ms
09-27 07:39:16.400: D/dalvikvm(11622): WAIT_FOR_CONCURRENT_GC blocked 7ms
09-27 07:39:16.400: I/TwitterImpl(11622): Uploading Image :: ubgthyghu.com2013923.png, message :: fred
09-27 07:39:16.405: D/ShareButtonActivity(11622): u got an error haus
09-27 07:39:16.405: W/System.err(11622): org.brickred.socialauth.exception.SocialAuthException: Image Upload Error
09-27 07:39:16.405: W/System.err(11622): at org.brickred.socialauth.android.SocialAuthAdapter.uploadImage(SocialAuthAdapter.java:1137)
09-27 07:39:16.405: W/System.err(11622): at com.example.twitter_stuff.ShareButtonActivity.post_image(ShareButtonActivity.java:273)
09-27 07:39:16.405: W/System.err(11622): at com.example.twitter_stuff.ShareButtonActivity$ResponseListener$1.onClick(ShareButtonActivity.java:171)
09-27 07:39:16.405: W/System.err(11622): at android.view.View.performClick(View.java:4223)
09-27 07:39:16.405: W/System.err(11622): at android.view.View$PerformClick.run(View.java:17281)
09-27 07:39:16.405: W/System.err(11622): at android.os.Handler.handleCallback(Handler.java:615)
09-27 07:39:16.405: W/System.err(11622): at android.os.Handler.dispatchMessage(Handler.java:92)
09-27 07:39:16.405: W/System.err(11622): at android.os.Looper.loop(Looper.java:137)
09-27 07:39:16.405: W/System.err(11622): at android.app.ActivityThread.main(ActivityThread.java:4898)
09-27 07:39:16.405: W/System.err(11622): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 07:39:16.410: W/System.err(11622): at java.lang.reflect.Method.invoke(Method.java:511)
09-27 07:39:16.410: W/System.err(11622): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
09-27 07:39:16.410: W/System.err(11622): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
09-27 07:39:16.410: W/System.err(11622): at dalvik.system.NativeStart.main(Native Method)
09-27 07:39:16.440: D/SocialAuthError(11622): org.brickred.socialauth.exception.SocialAuthException: Failed to update status on http://api.twitter.com/1.1/statuses/update.json?status=hjjhhj. Status :403
09-27 07:39:16.440: D/ShareButton(11622): Authentication Error: Message Not Posted
09-27 07:39:16.455: D/SocialAuthError(11622): org.brickred.socialauth.exception.SocialAuthException: Failed to update status on http://api.twitter.com/1.1/statuses/update.json?status=hjjhhj. Status :403
09-27 07:39:16.455: D/ShareButton(11622): Authentication Error: Message Not Posted

我知道这准备起来相当困惑 - 抱歉,但需要修复的主要代码是这样的:

int returnvalue  = adapter.uploadImage("fred", "ubgthyghu.com2013923.png", bitmap2, 3);

最佳答案

使用adapter.uploadImageAsync 您正在对 main ui 威胁 隐式执行 http 操作。 Android 不喜欢这样

关于java - android 新手 - 如何使用 SocialAuthAdapter 类中找到的 'uploadImage' 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19053492/

相关文章:

java - 一个java应用程序可以有多少个线程池

java.lang.IllegalArgumentException : object is not an instance of declaring class 异常

java - 如何从一个 Activity 访问一个方法并将其用于 Android 中的另一个 Activity?

android - Kotlin 如何将 Long 转换为 Int?为超出范围的值获取不同的输出

javascript - 构建用于推文的 chrome 扩展

java jython 导入错误

java - 尝试运行简单的 Android JUnit 测试。获取 : "Test run failed: No test results" What am I missing?

java - 如何在抽屉导航中创建可选标题

php - 为什么我不能更新我们的 Twitter 状态?

ios - Tweetbot URL Scheme 没有打开用户