Twitter Bearer token problem with Corona Simulator

I am implementing the Twitter API (application only authorization).

The 1st step is to request a Bearer token.  It is simple HTTP POST with a authorization header and a custom payload.

I successfully execute that request on my Chrome browser (using Advance REST client extension) and using curl on my MAC terminal.

But for some reason, when using the network.request on the Corona simulator, I get a denied access from twitter:

RESPONSE: {“errors”:[{“code”:99,“message”:“Unable to verify your credentials”,“label”:“authenticity_token_error”}]}

I tested on a Android device and it works.  So I only get an error on the Corona Simulator.

Any idea why? 

Here is the curl command that works:

curl -d "grant\_type=client\_credentials" -H "Authorization:Basic T3V6V2F1dzhaUWh2VE9SQk1vVFlMeWJ1Mjp0Q2F4dHM0am82Z2lZWVQzN0xrMkt6RERpTkNYcEZVb01reEJJNzN6anR0bEFBb21FbA==" https://api.twitter.com/oauth2/token

Here is my lua code that works on the device but not on the Corona Simulator:

local function networkListener( event ) if ( event.isError ) then print( "Network error!" ) else print ( "RESPONSE: " .. event.response ) end end local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Authorization"] = "Basic T3V6V2F1dzhaUWh2VE9SQk1vVFlMeWJ1Mjp0Q2F4dHM0am82Z2lZWVQzN0xrMkt6RERpTkNYcEZVb01reEJJNzN6anR0bEFBb21FbA==" local body = "grant\_type=client\_credentials" local params = {} params.headers = headers params.body = body network.request( "https://api.twitter.com/oauth2/token", "POST", networkListener, params )

UPDATE:

After sniffing the request I found that the Corona Simulator is sending a cookie that is making the request fail. The cookie is:

auth_token=088598bffa8bb985387e17fc0880c12a3e5c9de0;

I just need know to find out how to clear the cookies from the Simulator. Anyone?

SOLUTION:

 

Just found out that clearing all the cookies from Safari will solve the problem.

You may also be interested in the free Twitter plugin: https://forums.coronalabs.com/topic/58033-twitter-plugin-is-available-now/

The plugin does not have support to application-only authorization… But thanks anyway!

You may also be interested in the free Twitter plugin: https://forums.coronalabs.com/topic/58033-twitter-plugin-is-available-now/

The plugin does not have support to application-only authorization… But thanks anyway!