Android Twitter4j getting error while retweet or send message
I am making an app for twitter integration using Twitter4j API.
Right now my problem is, when i tried to make retweet or send direct messages like:
twitter.retweetStatus(sid); twitter.sendDirectMessage(uid, msg);
i got the following error:
> 08-20 11:11:17.409: WARN/System.err(233): 403:The request is
> understood, but it has been refused. An accompanying error message
> will explain why. This code is used when requests are being denied due
> to update limits
> (http://support.twitter.com/forums/10711/entries/15364). 08-20
> 11:11:17.409: WARN/System.err(233): Relevant discussions can be on the
> Internet at: 08-20 11:11:17.409: WARN/System.err(233):
> http://www.google.co.jp/search?q=dbd7edaf or 08-20 11:11:17.409:
> WARN/System.err(233): http://www.google.co.jp/search?q=012e63a7
> 08-20 11:11:17.409: WARN/System.err(233):
> TwitterException{exceptionCode=[dbd7edaf-012e63a7], statusCode=403,
> retryAfter=0, rateLimitStatus=null, version=2.1.11} 08-20
> 11:11:17.409: WARN/System.err(233): at
> twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:199)
> 08-20 11:11:17.419: WARN/System.err(233): at
> twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:75)
> 08-20 11:11:17.419: WARN/System.err(233): at
> twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:128)
> 08-20 11:11:17.419: WARN/System.err(233): at
> twitter4j.Twitter.retweetStatus(Twitter.java:661) 08-20 11:11:17.419:
> WARN/System.err(233): at
> com.openxcell.zoodig.TimelineRe$3.onClick(TimelineRe.java:98) 08-20
> 11:11:17.419: WARN/System.err(233): at
> android.view.View.performClick(View.java:2344) 08-20 11:11:17.419:
> WARN/System.err(233): at
> android.view.View.onTouchEvent(View.java:4133) 08-20 11:11:17.419:
> WARN/System.err(233): at
> android.widget.TextView.onTouchEvent(TextView.java:6510) 08-20
> 11:11:17.429: WARN/System.err(233): at
> android.view.View.dispatchTouchEvent(View.java:3672) 08-20
> 11:11:17.429: WARN/System.err(233): at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) 08-20
> 11:11:17.429: WARN/System.err(233): at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) 08-20
> 11:11:17.429: WARN/System.err(233): at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) 08-20
> 11:11:17.429: WARN/System.err(233): at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) 08-20
> 11:11:17.429: WARN/System.err(233): at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) 08-20
> 11:11:17.429: WARN/System.err(233): at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) 08-20
> 11:11:17.439: WARN/System.err(233): at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) 08-20
> 11:11:17.439: WARN/System.err(233): at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) 08-20
> 11:11:17.439: WARN/System.err(233): at
> com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1712)
> 08-20 11:11:17.439: WARN/System.err(233): at
> com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1202)
> 08-20 11:11:17.439: WARN/System.err(233): at
> android.app.Activity.dispatchTouchEvent(Activity.java:1987) 08-20
> 11:11:17.439: WARN/System.err(233): at
> com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1696)
> 08-20 11:11:17.439: WARN/System.err(233): at
> android.view.ViewRoot.handleMessage(ViewRoot.java:1658) 08-20
> 11:11:17.449: WARN/System.err(233): at
> android.os.Handler.dispatchMessage(Handler.java:99) 08-20
> 11:11:17.449: WARN/System.err(233): at
> android.os.Looper.loop(Looper.java:123) 08-20 11:11:17.449:
> WARN/System.err(233): at
> android.app.ActivityThread.main(ActivityThread.java:4203) 08-20
> 11:11:17.449: WARN/System.err(233): at
> java.lang.reflect.Method.invokeNative(Native Method) 08-20
> 11:11:17.449: WARN/System.err(233): at
> java.lang.reflect.Method.invoke(Method.java:521) 08-20 11:11:17.459:
> WARN/System.err(233): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
> 08-20 11:11:17.470: WARN/S开发者_开发问答ystem.err(233): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 08-20
> 11:11:17.470: WARN/System.err(233): at
> dalvik.system.NativeStart.main(Native Method)
Can anyone please tell me why i am getting this? is there anything problem with api? or where i am making mistake?
Any Help Regarding this will be Appreciated..
Thank You, Mayur Parekh
The stacktrace that you have provided contains a message which tells you what happened.
From the stacktrace:
403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (http://support.twitter.com/forums/10711/entries/15364)
The link provided in the message suggests that there are some API limits. Here is the message from the page:
Limits alleviate some of the strain on the behind-the-scenes part of Twitter, and reduce downtime and error pages. For the sake of reliability, we've placed some limits on account actions like following, API requests, direct messages, and updates.
Here is the breakdown of the various limits:
- Direct Messages: 250 per day.
- Updates: 1,000 per day. The daily update limit is further broken down into smaller limits for semi-hourly intervals. Retweets are counted as updates.
- Changes to Account Email: 4 per hour.
- Following (daily): Please note that this is a technical account limit only, and there are additional rules prohibiting aggressive following behavior. You can find detailed page describing following limits and prohibited behavior on the Follow Limits and Best Practices Page. The technical follow limit is 1,000 per day.
- Following (account-based): Once an account is following 2,000 other users, additional follow attempts are limited by account-specific ratios. The Follow Limits and Best Practices Page has more information.
in my case i was getting this error cause the response was not just a JSON Object
but that was a JSON Array
and i was trying to conver it into JSONObject directly..
So the error is resolved now.
Thank You @nicholas your answer helped me alot..
Recently I got the same error while executing similar code. To fix it, follow these steps:
- Go to https://apps.twitter.com/app/your_app_id
- Click on Keys and access token
- In Access Level, click modify app permission and choose the 3rd option: Read, Write and Access direct messages
- Click on update. ( Note: you might have to add your mobile no and verify with otp to get this access if you don't have your no added in twitter)
- Regenerate both Consumer key & secret and Access token & secret using the click-able button
And you are done! Your program will start working.
精彩评论