Auth Error Code 99: HTTP Response 403

auth
error-codes

#1

Hello,

About two days ago, I started receiving a new error code upon attempting client-credentials authorization. My code has not changed at all, so I’m left to wonder if I have been rate limited or something else? I will share the request code.

def auth(self):
    # get the bearer token by issuing a request to the api with the auth_string
    # using application-only auth method. https://dev.twitter.com/docs/auth/application-only-auth
    # declare the consumer key and secret, concat them, and base64 encode them
    params = {'grant_type':'client_credentials'}
    auth_string = self.consumer_key+':'+self.consumer_secret
    auth_string_b64 = base64.b64encode(auth_string)
    headers = {
        'Authorization': 'Basic ' + auth_string_b64,
        'content-type':'application/x-www-form-urlencoded;charset=UTF-8'}
    r = requests.post('https://api.twitter.com/oauth2/token',headers=headers,data=params).json()
    self.access_token = r["access_token"]
    return 

This auth call will yield the following response:
Out[45]: Response 403
In [46]: r.content
Out[46]: '{"errors":[{"code":99,"message":"Unable to verify yourcredentials",“label”:“authenticity_token_error”}]}’

Have they changed something with the API? I would imagine they are in a code freeze now?

Thanks,
Alex


#2

Hi,

I got the same issue. My Java code looks like this:

String consumerKey = "123somethin13g1234Key";
String consumerSecret = "123somesdfthing1234KeySecret";
String credentials = consumerKey + ":" + consumerSecret;
String credentialsEncoded = Base64.encodeToString(credentials.getBytes("UTF-8"), Base64.NO_WRAP);
URL url = new URL("https://api.twitter.com/oauth2/token"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(15000); conn.setConnectTimeout(15000); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestProperty("User-Agent", "My Twitter App v1.0.23"); conn.setRequestProperty("Host", "api.twitter.com"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); conn.setRequestProperty("Authorization", "Basic " + credentialsEncoded); conn.setRequestProperty("Accept-Encoding", "gzip"); OutputStream os = conn.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); writer.write("grant_type=client_credentials"); writer.flush(); writer.close(); os.close(); int responseCode = conn.getResponseCode(); Log.d(DEBUG_TAG, "responseCode = " + responseCode);

its always returning HTTP 403. When running this curl command it is the same:

curl --request ‘POST’ ‘https://api.twitter.com/oauth2/token’ --header ‘Authorization: Basic c29tZXRoaW5nMTIzNEtleTpzb21ldGhpbmcxMjM0S2V5U2VjcmV0’ --header ‘Content-Type: application/x-www-form-urlencoded;charset=UTF-8’ --data “grant_type=client_credentials” --verbose

What is wrong here?