Re: need help with code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Code without proper indentation and is very hard to comprehend. You have
unnecessary spacing and line breaks that makes it difficult to debug.

I suggest you few things as a good practice:

1) Until you learn perfectly to code use some nice GUI editors that have
syntax highlighting (aptana, eclipse, zend etc).
2) Don't try to mix up markup (html) and api calls(PHP Code). Believe it
become a horrible mess to maintain after some point.

Anyways Here is your code with parse error removed:

<?php
require_once('twitterlib.php');

$consumerKey="yVVRd1QCJYBtT8tT7ocg";

$consumerSecret="DHzhJYOP2hBWfHpHawGxRQEFf98nF4TBTfabel2ukE";
$accessToken = $_COOKIE['accessToken'];
$reqToken = $_COOKIE['reqToken'];

if($accessToken===NULL){
  if ($reqToken === NULL){
    //get a req token
    $to = new TwitterOAuth($consumerKey, $consumerSecret);
    $tok = $to->getRequestToken();
    $reqToken = $tok['oauth_token'];
    $reqTokenSecret = $tok['oauth_token_secret'];
    $request_link = $to->getAuthorizeURL($toc);
    $content = 'Click on the link to go to twitter to authorize your
account.';
    $content .= '<br /><a href="'.$request_link.'">'.$request_link.'</a>';
    setCookie('reqToken',$reqToken,time()+(24*30*60*60),'/');
    setCookie('reqTokenSecret',$reqTokenSecret,time()+(24*30*60*60),'/');

    ?>
    <html><head><title>authorize</title></head><body>
    <?php echo $content;?>
    </body></html>
    <?php
   }else{
    /* If the access tokens are already set skip to the API call */
    if ($_COOKIE['accessToken']===NULL){
      /* Create TwitterOAuth object with app key/secret and token key/secret
from default phase */
      $to = new
TwitterOAuth($consumerKey,$consumerSecret,$_COOKIE['reqToken'],$_COOKIE['reqTokenSecret']);

      /* Request access tokens from twitter */
      $tok = $to->getAccessToken();
      /* Save the access tokens. Normally these would be saved in a database
for future use.*/

setCookie('accessToken',$tok['oauth_token'],time()*24*60*60*30+3600,'/');

setCookie('accessTokenSecret',$tok['oauth_token_secret'],time()*24*60*60*30,'/');
      header("location http://www.chriswestbrook.com/twitter/twitter.php";);

    }
  }
}
?>

Thanks,
V

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux