Post to Twitter with PHP


#1

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: http://twitter.chris-alexander.com 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 https://github.com/cmalexander/php-post-to-twitter/tree/master

Any help or direction would be greatly appreciated!

Chris


#2

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.

Hamza


#4

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.

cmalexander