Hi Paul,

> 1. Do I need to upgrade to OAuth?

Twitter are killing off basic authentication on 16th August, so you'll
need to upgrade.

> 2. If I need to upgrade to OAuth, can it be done in such a way as to
> work without browser login and redirect requirements? (as per example)

The Twitter OAuth tokens don't currently expire so you could do the
auth once then store the tokens for later non-interactive use.

> 3. If 2 is true, any tutorials that match that situation you can point
> me to?

Don't know if you're tied to a current library but 
does a good job of OAuth.

Rough process:

One off:

1) Login to your company Twitter account.
2) Settings -> Connections -> Click the link under Developers at
bottom right.  Takes you to: http://twitter.com/apps
3) Register your app.  You can get away with as the callback
URL if you're running a local webserver, but it's not so important if
you're just doing this as a one off as you can specify callback URL at
request time.

You'll probably want:

Type: Browser
Access Type: Read & Write
Use Twitter for login: No

This will get you your consumer key & secret.

4) Assuming use of twitter-async, here's some scrappy code that'll get
you your tokens:


require_once "twitter-async/EpiCurl.php";
require_once "twitter-async/EpiOAuth.php";
require_once "twitter-async/EpiTwitter.php";

define( "CONSUMER_KEY", "XXXXX" );

$twitter = new EpiTwitter( CONSUMER_KEY, CONSUMER_SECRET );

if( isset( $_GET["oauth_token"] ) )
                $twitter->setToken( $_GET["oauth_token"] );
                $token = $twitter-
>getAccessToken( array( "oauth_verifier" =>
$_GET["oauth_verifier"] ) );
                var_dump( $token->oauth_token, $token-
>oauth_token_secret );
        catch( Exception $e )
                var_dump( get_class( $e ) );
        header( "Location: " . $twitter->getAuthorizeUrl( null,
array( "oauth_callback" => "
path_to_this_script.php" ) ) );


Obviously change the callback URL to point to wherever you host this
script, and fill in your consumer key/secret.

After you've authed the account, twitter will bring you back and the
script will spit out your oauth_token and oauth_secret.

So from now on if you want to tweet, you simply:

$twitter->post_statusesUpdate( array( "status" => "Something exciting
happened!" ) );

There's probably an easier way to get the tokens, but this worked well
for me.

Hope this helps,
- Paul

Reply via email to