How to output to html


#1

Hi,

i am trying to make my own Twitter widget for my own website to show my home_timeline.

I have made my own app got the various keys and it is authenticated.

I’m using Abrahams twitteroauth.

Have got it to output the content to my browser screen but cannot figure out how to have it formatted to HTML.

Here is the code from my php file:-

<?php

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

    $connection = new TwitterOAuth (CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET); 
	
	$content = $connection->get("statuses/home_timeline");
	
include('html.inc');

Here is the code from the html.inc file:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>Twitter OAuth in PHP</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <style type="text/css">
      img {border-width: 0}
      * {font-family:'Lucida Grande', sans-serif;}
    </style>
  </head>
  <body>
    <div>
      
      <hr />
      <?php if (isset($menu)) { ?>
        <?php echo $menu; ?>
      <?php } ?>
    </div>
    <?php if (isset($status_text)) { ?>
      <?php echo '<h3>'.$status_text.'</h3>'; ?>
    <?php } ?>
    <p>
      <pre>
        <?php print_r($content); ?>
      </pre>
    </p>
    </body>
</html>

I would like it to format as:-
profile image, user name, text, date

into some kind of table or div, this bit I can figure out myself, it’s just how do I extract the various pieces of data from the massive $content output?

Any help would be appreciated.

Kind regards…,

MT


#2

replace this part of the code …

        <?php print_r($content); ?>
      

with a loop through the the $content Array with Objects

foreach ($content as $item) {
// … loop of content array … each result as $item
}

Tweet data as $item->[OBJECT_NAME]
User data as $item->user->[OBJECT_NAME]

… simple example:

<?php

foreach ($content as $item) { // ---- start foreach ----

echo “<div class=“userdata” style=“clear:both; padding:8px; margin:10px; border: 1px solid #AAAAAA; background:#FFFFAA; width:570px; text-align:left;”> \r\n”;

echo “<img src=”". $item->user->profile_image_url ."" style=“border:none; width:40px; float:left; padding:0px 8px 4px 0px;” /> \r\n";
echo “User: <a href=“http://twitter.com/#!/”. $item->user->screen_name .”" target="_blank">". $item->user->screen_name ." \r\n";
echo "
Name: “. $item->user->name .”\r\n";
echo “\r\n”;
echo "
Friends: “. $item->user->friends_count .”\r\n";
echo "    Follower: “. $item->user->followers_count .” \r\n";
echo "    Listed: “. $item->user->listed_count .” \r\n";
echo "    Favourites: “. $item->user->favourites_count .” \r\n";
echo "    Tweets: “. $item->user->statuses_count .” \r\n";

echo "
Location: “. $item->user->location .” \r\n";
echo "
Language: “. $item->user->lang .” \r\n";

echo "
User URL: “. $item->user->url .” \r\n";

echo "
Description: “. $item->user->description .” \r\n";
echo “\r\n”;

echo "
  \r\n";

echo “<span class=“thetweet” style=“padding:6px; background:#DEDEDE; line-height:16px; display:block;”> \r\n”;
echo $item->text ."\r\n"; // — the status text = the tweet —
echo " \r\n";

echo “\r\n”;
echo "
    direct link to <a href=“http://twitter.com/#!/”. $item->user->screen_name ."/statuses/". $item->id_str ."" traget="_blank">TWEET \r\n";
echo “
\r\n”;

echo "
  \r\n";
echo "
Date: “. $item->created_at .” \r\n";
echo "
Souce: “. $item->source .” \r\n";
echo "
  \r\n";

echo " \r\n";

} // ---- end foreach ----

// --------- DEBUG data ---------

echo “
\r\n”;

print_r($content);

echo “\r\n”;

?>

loop the content Array (foreach) and print out (echo) the objects values of each item
if you put a # on the begin of a line this line will not be executed (eg. User URL)
you can change style/html … and even better: set styles by classes in css-file
… also see example here: https://dev.twitter.com/discussions/1169


#3

hi
how i save html.inc to xml in my server

is the code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

  <head>

    <title>Twitter OAuth in PHP</title>

    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

    <style type="text/css">

      img {border-width: 0}

      * {font-family:'Lucida Grande', sans-serif;}

    </style>

  </head>

  <body>

    <div>

 

      <hr />

      <?php if (isset($menu)) { ?>

        <?php echo $menu; ?>

      <?php } ?>

    </div>

    <?php if (isset($status_text)) { ?>

      <?php echo '<h3>'.$status_text.'</h3>'; ?>

    <?php } ?>

    <p>

      <pre>

        <?php print_r($content); ?>

      </pre>

    </p>

    </body>

</html>

#4
Twitter OAuth in PHP img {border-width: 0} {font-family:'Lucida Grande', sans-serif;}


<?php if (isset($menu)) { ?> <?php echo $menu; ?> <?php }?>
<?php if(isset($status_text)){?> <?php echo '

'.$status?text.'

'; ?> <?php } ?>

<?php print_r($content); ?> 

#5
Twitter OAuth in PHP img {border-width: 0} {font-family:'Lucida Grande', sans-serif;}


<?php if (isset($menu)) { ?> <?php echo $menu; ?> <?php }?>
<?php if(isset($status_text)){?> <?php echo '

'.$status?text.'

'; ?> <?php } ?>

<?php print_r($content); ?> 

#6