Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 612605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:54:42+00:00 2026-05-13T17:54:42+00:00

I’m trying to make a simple site that uses php and the Twitter API

  • 0

I’m trying to make a simple site that uses php and the Twitter API to write out my latest post from twitter. I found a tutorial showing me how to get my timeline (or last 20 posts) in xml format, but can’t figure out how to print out just the latest post, and just the text of it (not the time, date, etc that come with the xml/rss/etc).

My code looks like this

<h2 id = "latest">
    <?php
        var $username='myusername';  
        var $password='mypassword'; 
        var $responseInfo=array();

        function latest_status($format='json',$id=null) {
            $request = 'http://twitter.com/statuses/user_timeline.'.$format;
            if($id) {
                $postargs = "id=$id";
                return $this->process($request,$postargs);
            }
            return $this->process($request);
        }

        echo latest_status("json");
    ?>
</h2>

And it’s returning this:

[{“contributors”:null,”created_at”:”Tue
Feb 16 19:56:08 +0000
2010″,”in_reply_to_user_id”:null,”source”:”API”,”favorited”:false,”in_reply_to_status_id”:null,”truncated”:false,”user”:{“notifications”:null,”profile_link_color”:”0000ff”,”description”:””,”verified”:false,”profile_background_tile”:false,”created_at”:”Tue
Feb 16 01:16:15 +0000
2010″,”profile_background_color”:”9ae4e8″,”profile_image_url”:”http://s.twimg.com/a/1265999168/images/default_profile_1_normal.png“,”time_zone”:”Hawaii”,”profile_sidebar_fill_color”:”e0ff92″,”followers_count”:0,”screen_name”:”whisperingweb”,”lang”:”en”,”friends_count”:0,”profile_sidebar_border_color”:”87bc44″,”statuses_count”:2,”following”:null,”protected”:false,”favourites_count”:1,”location”:””,”name”:”Chris
Armstrong”,”contributors_enabled”:false,”profile_text_color”:”000000″,”id”:114608397,”geo_enabled”:true,”profile_background_image_url”:”http://s.twimg.com/a/1265999168/images/themes/theme1/bg.png“,”utc_offset”:-36000,”url”:null},”in_reply_to_screen_name”:null,”geo”:null,”id”:9199090048,”text”:”Someone
was on your
website”},{“favorited”:false,”source”:”web”,”in_reply_to_user_id”:null,”created_at”:”Tue
Feb 16 18:50:21 +0000
2010″,”geo”:null,”user”:{“verified”:false,”description”:””,”notifications”:false,”profile_text_color”:”000000″,”screen_name”:”whisperingweb”,”profile_background_image_url”:”http://s.twimg.com/a/1265999168/images/themes/theme1/bg.png“,”url”:null,”profile_link_color”:”0000ff”,”followers_count”:0,”statuses_count”:2,”profile_background_tile”:false,”created_at”:”Tue
Feb 16 01:16:15 +0000
2010″,”friends_count”:0,”profile_background_color”:”9ae4e8″,”contributors_enabled”:false,”time_zone”:”Hawaii”,”favourites_count”:0,”profile_sidebar_fill_color”:”e0ff92″,”protected”:false,”location”:””,”name”:”Chris
Armstrong”,”lang”:”en”,”geo_enabled”:true,”profile_sidebar_border_color”:”87bc44″,”id”:114608397,”following”:false,”utc_offset”:-36000,”profile_image_url”:”http://s.twimg.com/a/1265999168/images/default_profile_1_normal.png“},”contributors”:null,”in_reply_to_status_id”:null,”id”:9196705546,”in_reply_to_screen_name”:null,”truncated”:false,”text”:”The
quick brown fox jumps over the lazy
dog”}]

I’m pretty new to php, and completely new to the Twitter API, so would appreciate any help or advice.

edit: Have changed example from xml to json

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:54:42+00:00Added an answer on May 13, 2026 at 5:54 pm

    Use format=’json’ instead: json_decode($response)[0][‘text’].

    In this case, use JSON because it has a much more natural mapping to PHP’s internal datatypes, which makes it dead-easy to extract the content you want. You can still use XML, but you have to iterate over the resulting structure, which is relatively complex.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.