Helper wrapper for Abraham Williams TwitterOAuth PHP wrapper

Recently Twitter has thrown the switch and killed basic-auth authentication for interaction with their Twitter API. This means you can no longer simply use cURL in the following manner to make status updates etc:-

curl --silent --user 'username:password' --data status='Hello World' 
http://api.twitter.com/1/statuses/update.json

You must now use their OAuth interface to do all the authentication and it's no surprise that OAuth is a more painful than a simple username/password mechanism. Make no mistake OAuth is good stuff it's just a lot to understand when you first see it.

The libraries that Twitter point to for PHP to are Abraham Williams TwitterOAuth wrapper which does a fine job of making life easy working with Twitter's OAuth. But there is still a hicup or sorts...

If you are a user that just wants to use the Twitter API in "single user mode" that is, you don't want to build an application that has the ability to make Twitter API calls on behalf of other users then the whole OAuth thing will seem like total overkill.

None the less OAuth is the way Twitter auth needs to be done so you either need to get in there and learn/understand it all or find some some other way. To that end I've put together a handy little console helper tool and wrapper to make life with Twitter OAuth even easier for developers that just want "single user mode" style functionality with the API.

The console tool guides a user through creating a twitteroauth.credentials file which can be used on it's own if you'd like. The wrapper class then makes use of the twitteroauth.credentials file that deals with with setting everything else up so then using the Twitter API is now almost as simple as it was in the days of basic-auth.

For example to send a tweet:-

include('twitteroauth-helper-wrapper.php');
$TOHW = new TwitterOAuthWrapper('/path/to/credentials.file');
$TOHW->post('statuses/update',array('status'=>'Hello World!'));

Which is about as easy as the old-school http-auth way... and you do not have to have to learn anything about OAuth - not a drop, it just works.

Go ahead and grab the package here:-
http://github.com/downloads/ndejong/twitteroauth-helper/twitteroauth-hel...

Source at GitHub:-
http://github.com/ndejong/twitteroauth-helper

THANK YOU SO MUCH!!! I could

THANK YOU SO MUCH!!!

I could never follow any TwitterOAuth tutorials for PHP and I was ready to give up until I finally found your site. I wish I had found it sooner! I'm running two bots now, @SurfinBot and @RebeccaBBot, using your brilliantly simplified wrapper.

May I link back to your page from mine? I want to spread the word for anyone else interested in writing a Twitter bot. I might even publish the basic source code that I base my bots off of once I refine it a little more.

One other question: How did you write that command line app in PHP? I want to know how to write php scripts that can take in user input like your console app does, because aside from making bots I want to write a Twitter client similar to TTYtter in PHP to use with my Apple II (which acts as a serial terminal).

Hi, the problem im facing is,

Hi, the problem im facing is, after I give the command request_user_auth nothing happens. Can you tell me step by step procedure?
Btw great work, ive been looking for this all over :)

Thanks
Vishnu

Hi- This looks to be exactly

Hi-

This looks to be exactly what I need!

I downloaded the package and uploaded to my Linux server. I got shell access and attempted to run the console... to no avail.

I know this is a noob question, but what would be the commands for running the console in a shell?

Appreciated.

JTG

Hi JTG, Sounds like you might

Hi JTG,

Sounds like you might have some learning to go but in short you'll need to go through the following motions:-

(a) download the package
shell> wget http://github.com/downloads/ndejong/twitteroauth-helper/twitteroauth-hel...

(b) untar the file
shell> tar -zxvf twitteroauth-helper.0.1.tar.gz

(c) ... then start the console app
shell> ./twitteroauth-helper/twitteroauth-helper-console

then follow the readme

Hope this helps.
N

N- Thanks. I guess there must

N-

Thanks. I guess there must be something I am missing on my server... I get a "bad interpreter" error when trying to execute the console :(

Ahh - you need to make sure

Ahh - you need to make sure you have php-cli installed

Okay... Got Shell Access

Okay...

Got Shell Access (yay!)
Got access to PHP -cli (yay!)
Ran console (yay!)

Got error: Fatal error: func_get_args(): Can't be used as a function parameter in /home/gridiron/public_html/OAuth/twitteroauth-helper/twitteroauth-helper-console on line 55

:(

Any insight Nicholas?

Thanks.
John

Hi John, This seems to be a

Hi John,

This seems to be a issue with PHP, see here:-
* http://bugs.php.net/bug.php?id=34120

My sense is that since this seems to work for me (and others) but it is not working for you then it is probably a matter that was fixed in a more recent version of PHP.

There are two ways to deal with this, either (a) upgrade your PHP or (b) you can just comment out the offending line as you will see that it's only purpose is to capture Debug console output anyway!

Hope this helps.

N

Thank you, this helped a lot!

Thank you, this helped a lot!

No problem - happy to hear it

No problem - happy to hear it helped someone out - N

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.