A tip about tweeting from a PHP app using OAuth

I followed this excellent tutorial by Adam Green;


but for the life of me I couldn’t get it to work; I kept getting a 401 return code saying that my app did not have write access.
But, I had given it write access so…what happened!?

Actually, the cause and effect, and subsequent fix, was simple but not entirely obvious;
I had created the app as a READ ONLY app to start with and generated all the codes for it.
I then had realised my mistake and set the app permissions to Read & Write. The dev.twitter.com page for my subsequently showed me that me that the app now had the required access.
Still, I got a 401 error back.

I had not, however, recreated my access tokens (there’s a button for this at the bottom of the page.)
Once I did this the app worked.

So; the confusingly named “Access Token” and “Access Token Secret” need to be regenerated if you change the permissions for your app. This is not obvious to me since I would expect these tokens to encode the identiy of the app and therefore allow Twitter to access its permissions through the back-end…
But there you go, at least now it works.