OK guys, I am really tickled to have finally worked out a reasonable
understanding of how to use Abraham's Twitter Oauth for making
automated status updates. You're right, it is easy. And it's fun!
Thank you, thank you, Abraham, for making this available!!!

For anyone else who may be struggling with how to move from PHP
curl/basic authentication to Oauth, here's a quick tip:

Focus on Abraham's test.php file. Register callback.php as your app,
but load test.php in your browser. COMMENT OUT everything in the
script that doesn't interest you, because it will create/alter/delete
everything in your twitter account. (I had to comment stuff out
because I was unable to create a test account.) Edit config.php

At Twitter.com go to your apps listing and retrieve your consumer key
and consumer secret. Click on the My Access Token button to get your
access token and access secret.

I'll paste a very stripped down version of test.php below, in case
this is helpful to anyone. After edited with your keys and tokens,
then loaded in a browser, this will post status updates.

?php
/**
 * @file
 *
 */

/* Load required lib files. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');


session_start();
$_SESSION['access_token'] = 'YOURACCESSTOKENSTRING'; // store session data
session_start();
$_SESSION['oauth_token_secret'] = 'YOURACCESSTOKENSECRET'; // store session data



/* If access tokens are not available redirect to connect page. */
if (empty($_SESSION['access_token']) ||
empty($_SESSION['access_token']['oauth_token']) ||
empty($_SESSION['access_token']['oauth_token_secret'])) {
    header('Location: ./clearsessions.php');
}
/* Get user access tokens out of the session. */
$access_token = $_SESSION['access_token'];

/* Create a TwitterOauth object with consumer/user tokens. */

function getConnectionWithAccessToken($oauth_token, $oauth_token_secret) {
  $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,
$oauth_token, $oauth_token_secret);
  return $connection;
}


$connection = getConnectionWithAccessToken("YOURACCESSTOKENSTRING",
"YOURACCESSTOKENSTRING");



/* Get logged in user to help with tests. */
$user = $connection->get('account/verify_credentials');

$active = TRUE;


function twitteroauth_row($method, $response, $http_code, $parameters = '') {

  if (!is_string($response)) {
    $response = print_r($response, TRUE);
  }
  if (!is_string($parameters)) {
    $parameters = print_r($parameters, TRUE);
  }


}



/* statuses/update */

$parameters = array('status' => 'YOUR STATUS UPDATE HERE MUST BE UNIQUE');
$status = $connection->post('statuses/update', $parameters);
twitteroauth_row('statuses/update', $status, $connection->http_code,
$parameters);

Reply via email to