0
votes

I am facing an issue in getting the twitter bearer token for my application.

Although, I received the successful response from Twitter as mentioned below: "POST https://api.twitter.com/oauth2/token?grant_type=client_credentials returned a response status of 200 OK".

But when I try to retrieve the bearer token from the response by using the below statement, I get a long queue of junk characters:

String str = response.getEntity(String.class);

Further to that i tried two more approaches:

1) The getHeaders method returned:

content-disposition=[attachment; filename=json.json]

So, it looks like that server is sending back the token in an attachment file so I changed the above to:

File r_file = response.getEntity(File.class);

But this temp file also consists of junk characters only

2) I tried to decode these characters using Base64, but even that threw back an error.

2

2 Answers

0
votes

Are you writing your application in Java, or something else ? here's a link from twitter documentation on examples for a number of languages

-1
votes

I had the same problem. I was trying to get the Bearer token from Android client using the Volley library for the network connection. The response status was 200 OK, however the response body was a string, full of funny junk characters.
I was setting manually 3 headers :

"Authorization": "Basic .....", 
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
"Accept-Encoding": "gzip"

After removing the "Accept-Encoding" header everything went OK. The response was the expected well formatted JSON:

{"token_type": "bearer", "access_token": "......."}