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 (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-an


#1

Sir when i try to upload mp3 files this Exception accours


#2
package twitter4j.examples.tweets; import twitter4j.Status; import twitter4j.Twitter; import twitter4j.TwitterException; import twitter4j.TwitterFactory; import twitter4j.auth.AccessToken; import twitter4j.auth.OAuthAuthorization; import twitter4j.auth.RequestToken; import twitter4j.User;

import twitter4j.conf.Configuration;
import twitter4j.conf.ConfigurationBuilder;
import twitter4j.media.ImageUpload;
import twitter4j.media.ImageUploadFactory;
import twitter4j.media.MediaProvider;

import java.io.File;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import twitter4j.StatusUpdate;
public final class UploadFile{
public static void main(String []args){
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(“1nDb8smSxycJffCQbVo0pg”)
.setOAuthConsumerSecret(“pkGmEnnt5QCzH6vx0Jy9qACLifYbGtPptleBc5KoT0”)
.setOAuthAccessToken(“2324979350-gKBvoFNGEEByUGUeHL6GwnTCvZuIWko8RDwjluY”)
.setOAuthAccessTokenSecret(“elxRIev6G72u4jXe8v7AfeV5WDNaEcHAVk2NgLSlHSl5E”);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();

try {

        try {
            // get request token.
            // this will throw IllegalStateException if access token is already available
            RequestToken requestToken = twitter.getOAuthRequestToken();
            System.out.println("Got request token.");
            System.out.println("Request token: " + requestToken.getToken());
            System.out.println("Request token secret: " + requestToken.getTokenSecret());
            AccessToken accessToken = null;

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            while (null == accessToken) {
                System.out.println("Open the following URL and grant access to your account:");
                System.out.println(requestToken.getAuthorizationURL());
                System.out.print("Enter the PIN(if available) and hit enter after you granted access.[PIN]:");
                String pin = br.readLine();
                try {
                    if (pin.length() > 0) {
                        accessToken = twitter.getOAuthAccessToken(requestToken, pin);
                    } else {
                        accessToken = twitter.getOAuthAccessToken(requestToken);
                    }
                } catch (TwitterException te) {
                    if (401 == te.getStatusCode()) {
                        System.out.println("Unable to get the access token.");
                    } else {
                        te.printStackTrace();
                    }
                }
            }
            System.out.println("Got access token.");
            System.out.println("Access token: " + accessToken.getToken());
            System.out.println("Access token secret: " + accessToken.getTokenSecret());
        } catch (IllegalStateException ie) {
            // access token is already available, or consumer key/secret is not set.
            if (!twitter.getAuthorization().isEnabled()) {
                System.out.println("OAuth consumer key/secret is not set.");
                System.exit(-1);
            }
        }
         String screenName = twitter.getScreenName();
           System.out.println("Connected to"+screenName);
    StatusUpdate status = new StatusUpdate("STATUS_TEXT");
    status.setMedia(new File("C:\\images\\teri_saanso_mein.mp3"));// BY SPECIFYING FILE PATH
    //status.setMedia("File name", new FileInputStream("")); // By InputStream
    Status updateStatus =twitter.updateStatus(status);
    long id = updateStatus.getId(); // id of the status posted
        System.out.println("Successfully updated the status to [" + updateStatus.getText() + "].");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get timeline: " + te.getMessage());
        System.exit(-1);
    } catch (IOException ioe) {
        ioe.printStackTrace();
        System.out.println("Failed to read the system input.");
        System.exit(-1);
    }

}

}


Eror is-
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 (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following).
message - Error creating status.
code - 189

Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=01ece8e6 or
http://www.google.co.jp/search?q=9b25a65d
TwitterException{exceptionCode=[01ece8e6-9b25a65d], statusCode=403, message=Error creating status., code=189, retryAfter=-1, rateLimitStatus=null, version=3.0.5}
Failed to get timeline: 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 (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following).
message - Error creating status.
code - 189

at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:162)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:98)
at twitter4j.TwitterImpl.post(TwitterImpl.java:1965)
at twitter4j.TwitterImpl.updateStatus(TwitterImpl.java:275)
at twitter4j.examples.tweets.UploadFile.main(UploadFile.java:80)

Java Result: -1


#3

I have the same problem and I surely have not broken any limits. You meanwhile found any solution ?


#4

The exception is thrown because the connection is refused.
I am also getting this message:

03-11 13:59:48.912: E/TwitterOAuthView(32415): SSL is required.

I am assuming that, twitter4j uses plain http requests to obtain the data. Twitter API only allows secured connections.

From this article https://dev.twitter.com/docs/security/using-ssl:

“Since Feb 26, 2014, api.twitter.com is returning 403 status code for all non-SSL incoming traffic. Your client code should be able to handle this error.”


#5

http.useSSL=true
use this is twitter4j.properties file may be this will help you.


#6

I have also same problem .please any one tell me how it solve


#7

32 down vote accepted

I had this same error and upgrading to the latest version of twitter4j 3.0.5 (at the time of this writing) fixed the issue.

Get the latest here http://twitter4j.org/en/index.html#download

EDIT: I should mention that the version i was running was twitter4j 3.0.3. So by going to version 3.0.5 or 3.0.6 fixed the issue for me.


#8

Upgrading to latest version worked for me. I was using twitter4j 3.0.3, so current latest twitter4j-core-4.0.2 did the job.


#9

I am using latest twitter4j-core-4.0.2.But having the same problem.Please any one give me solution.


#10

ı have already same issue but, my twit range out of 150 character.


#11

Hello, I dont know what error i am getting here is my error log…

FATAL EXCEPTION: main
Process: vt.parthvora.smi, PID: 29529
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145)
at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292)
at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:197)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:254)
at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:137)
at twitter4j.HttpClientBase.request(HttpClientBase.java:57)
at twitter4j.HttpClientBase.post(HttpClientBase.java:86)
at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:115)
at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:92)
at twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:292)
at twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:287)
at vt.parthvora.smi.MainActivityFragment.loginToTwitter(MainActivityFragment.java:292)
at vt.parthvora.smi.MainActivityFragment.access$700(MainActivityFragment.java:49)
at vt.parthvora.smi.MainActivityFragment$5.onClick(MainActivityFragment.java:177)
at android.view.View.performClick(View.java:4497)
at android.view.View$PerformClick.run(View.java:18590)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5021)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
at dalvik.system.NativeStart.main(Native Method)

Can any one please help me to find what is the error. It is coming at line

RequestToken requestToken = twitter.getOAuthRequestToken();

Any help would be good…Thanks!!


#12

Can you please start a new thread for this issue, and include some sample code if you can? I don’t see any connection between your error and the original thread topic.


#13