从Android应用程序更新twitter上的状态

时间:2013-12-02 21:11:14

标签: android twitter twitter4j

我正在开发新的Android应用程序,我尝试更新我的Twitter帐户状态,但自动启动一些警报,但有一些奇怪,非常stange !! 我设置闹钟重复每一分钟尝试,但更新状态一次工作正常,然后工作然后没有工作,等等!!

知道我在警报接收器中执行此代码但我从另一个活动

登录的原因是什么

这是我的代码: -

private Boolean updateTwitterStatus (String tweet) {
        Log.d("Tweet Text", "> " + tweet);
        String status = tweet;
        try {
            ConfigurationBuilder builder = new ConfigurationBuilder();
            builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
            builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);

            // Access Token
            String access_token = twitterPreferences.getString(PREF_KEY_OAUTH_TOKEN, "");
            // Access Token Secret
            String access_token_secret = twitterPreferences.getString(PREF_KEY_OAUTH_SECRET, "");

            AccessToken accessToken = new AccessToken(access_token, access_token_secret);
            Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);

            Log.d("token", "token : " + access_token);
            Log.d("secret", "secret : " + access_token_secret);

            // Update status
            twitter4j.Status response = twitter.updateStatus(status);
            Log.e("response", "r :" + response);

            Log.d("Status", "> " + response.getText());
        } catch (TwitterException e) {
            // Error in updating status
            Log.d("Twitter Update Error", e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

logcat的: -

12-02 23:08:59.020: W/System.err(4188): Relevant discussions can be found on the Internet at:
12-02 23:08:59.020: W/System.err(4188):     http://www.google.co.jp/search?q=b2b52c28 or
12-02 23:08:59.020: W/System.err(4188):     http://www.google.co.jp/search?q=1206f222
12-02 23:08:59.020: W/System.err(4188): TwitterException{exceptionCode=[b2b52c28-1206f222], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.5}
12-02 23:08:59.020: W/System.err(4188):     at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:162)
12-02 23:08:59.020: W/System.err(4188):     at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
12-02 23:08:59.020: W/System.err(4188):     at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:98)
12-02 23:08:59.020: W/System.err(4188):     at twitter4j.TwitterImpl.post(TwitterImpl.java:1965)
12-02 23:08:59.020: W/System.err(4188):     at twitter4j.TwitterImpl.updateStatus(TwitterImpl.java:264)
12-02 23:08:59.020: W/System.err(4188):     at com.engahmedphp.successquotes.AlarmReceiver.updateTwitterStatus(AlarmReceiver.java:207)
12-02 23:08:59.020: W/System.err(4188):     at com.engahmedphp.successquotes.AlarmReceiver.onReceive(AlarmReceiver.java:163)
12-02 23:08:59.020: W/System.err(4188):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2816)
12-02 23:08:59.020: W/System.err(4188):     at android.app.ActivityThread.access$3200(ActivityThread.java:126)
12-02 23:08:59.020: W/System.err(4188):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2088)
12-02 23:08:59.020: W/System.err(4188):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-02 23:08:59.020: W/System.err(4188):     at android.os.Looper.loop(Looper.java:123)
12-02 23:08:59.020: W/System.err(4188):     at android.app.ActivityThread.main(ActivityThread.java:4633)
12-02 23:08:59.020: W/System.err(4188):     at java.lang.reflect.Method.invokeNative(Native Method)
12-02 23:08:59.020: W/System.err(4188):     at java.lang.reflect.Method.invoke(Method.java:521)
12-02 23:08:59.020: W/System.err(4188):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
12-02 23:08:59.020: W/System.err(4188):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
12-02 23:08:59.020: W/System.err(4188):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

我认为你的日志不完整。解决你的问题应该从现在开始。

同样在Android上永远不会使用。

     try {
     } catch(SomeException e)
        //this log isnt correct in android.util.Log method e 
        Log.d("Twitter Update Error", e.getMessage());
        e.printStackTrace();

用于错误记录Log#e

有时e.printStackTrace()可以在你的logcat上解除。请注意,请使用

Log.e(TAG, "some message", e)