Post to Twitter with PHP


I’m developing a mobile website that involves posting to Twitter. I needed a simple starting point to build upon and came across a website which had the perfect PHP code for doing what I needed.

Here is the code I found: DiscussDesk - PHP Code to Post to Twitter

Here is a Demo of it working on their site: Demo of PHP Posting to Twitter

I can’t seem to get this code working however. I have set up the app in Twitter Dev Dashboard, added the access keys to the config file, and have been a bit confused with the callback url. I have loaded the code to my own website at: so my first question it - would this URL I’ve loaded it to be the callback url? Would it be for both the Twitter App Dashboard and the php config file? I’ve seen other examples show something like: http://twitter.chris-alexander?source=twitter for one of them.

I’ve tried multiple iterations of the call back url like above, but maybe I’m missing something? The demo site that is above makes a call to Twitter and grabs the access tokens. You can see that the code works, but it seems I’m doing something wrong. Or, maybe this code is out of date?

I have added the code to a repository at

Any help or direction would be greatly appreciated!



Hi @cmalexander. The sample code you found seems quite outdated, and the endpoint you’re trying to access (statuses/update) doesn’t require a Callback URL. For authentication for this API, the only authentication you’ll need is User Context, which is basically your keys/tokens.

I’ll speak to some of my colleagues to see what other similar up-to-date examples they might have seen and get back to you soon.



Thanks so much! I’m familiar with PHP so that’s my rationale for going that route. If you can find other easy to understand examples, that would be great! It’s the form field in the index.php example that is a draw to me.

I look forward to hearing back from you.



I found this one that seems pretty up to date and has some good example API endpoints (in PHP). It’s also quite simple to follow (compared to others I came across):

Hope this helps you!

#6 is a live sample you can follow to implement the oauth flow and you can look at the source code. Clicking on “Sign in with Twitter” will walk you through each step.


Thanks @Hamza. I did come across this link you sent me last night. I’ll check it out again. Really appreciate the assistance. I might have more questions. :slight_smile:


Thanks @abraham. I have also explored your option and have gone through your steps. Trouble is when it’s all broken down like that I can’t figure out how to piece it all together. That’s why I liked the php that I posted above. I could see all the parts. But, maybe I’m over thinking your implementation? Are there any simple implementations that I can download or see that have a form field to type into and post after the user has authenticated? The only examples I’ve found have the post embedded in the php code like this:

$new_status = $connection->post("statuses/update", ["status"=>"This post was created using Twitter API built with PHP. #100DaysOfCode "]);

closed #9

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.