Hi Talasan, One of the reasons that that the TwitterOAuth example is split into multiple files with redirects is to keep different actions separate and easier to understand/debug. As your code currently is it is hard to tell what will happen when.
You also don't have any error handling if any of the requests to Twitter fail. You can do this by checking if $connection->http_code == 200 after each $connection function is executed. Are you actually visiting twitter.com to authorize access from the application? I see you getting a request token and generating the authorize URL but I don't see it being visited anywhere. This is required to get an access token. Your logic flow could be improved as well. Currently it is roughly: if no oauth_token parameter get request token else if no access token session get access token end end if submit tweet verify account post tweet end With the current flow every single execution will get a request token besides the one time you return from twitter.com and get an access token. I recommend you read through the documentation again and better understand what each step does and why it does it. https://github.com/abraham/twitteroauth/blob/master/DOCUMENTATION Abraham ------------- Abraham Williams | InboxQ <http://inboxq.com/> | abrah.am @abraham <https://twitter.com/abraham> | github.com/abraham | blog.abrah.am This email is: [ ] shareable [x] ask first [ ] private. On Tue, May 3, 2011 at 16:46, Talasan <talasan.nichol...@gmail.com> wrote: > I'm pretty lost! :) > > I've gone through the documents and I've once successfully posted a > tweet. No idea how that happened, however. I'm attempting to do a one- > page validation for this so that I can keep it relatively simple > without redirects. > > How can I accomplish this, however? Here is my code, and I'd greatly > appreciate somebody to point out the fallacies. Thank you. > > > if(!@$_GET['oauth_token']) { > $connection = new TwitterOAuth($db['twc_api'], > $db['twc_secret']); > $temp = $connection->getRequestToken($OAUTH_CALLBACK); > $twit_url = $connection->getAuthorizeURL($temp); > $_SESSION['oauth_request_token'] = $token = > $temp['oauth_token']; > $_SESSION['oauth_request_token_secret'] = > $temp['oauth_token_secret']; > } else { > if(!isset($_SESSION['oauth_access_token']) || > $_SESSION['oauth_access_token'] == '') { > $connection = new TwitterOAuth($db['twc_api'], > $db['twc_secret'], > $_SESSION['oauth_request_token'], > $_SESSION['oauth_request_token_secret']); > $temp = $connection->getRequestToken(); > $_SESSION['oauth_access_token'] = $token = > $temp['oauth_token']; > $_SESSION['oauth_access_token_secret'] = > $temp['oauth_token_secret']; > } > } > > if(isset($_POST['submit_tweet'])) { # Handle tweet submissions > $connection = new TwitterOAuth($db['twc_api'], > $db['twc_secret'], > $_SESSION['oauth_access_token'], > $_SESSION['oauth_access_token_secret']); > $content = $connection->get('account/verify_credentials'); > $msg = $_REQUEST['tweet']; > $update_status = $connection->post('statuses/update', array( > 'status' => $msg.' '.bitly($money_url, > $db['bitly_login'], > $db['bitly_api']) > )); > $tweeted = true; > print_r($update_status); > if($update_status->error) echo 'An error occurred'; > else Header('location: '.$reward_url); > } > > -- > Twitter developer documentation and resources: http://dev.twitter.com/doc > API updates via Twitter: http://twitter.com/twitterapi > Issues/Enhancements Tracker: > http://code.google.com/p/twitter-api/issues/list > Change your membership to this group: > http://groups.google.com/group/twitter-development-talk > -- Twitter developer documentation and resources: http://dev.twitter.com/doc API updates via Twitter: http://twitter.com/twitterapi Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list Change your membership to this group: http://groups.google.com/group/twitter-development-talk