• 0

PHP Snippet: Twitter Info and last 10 status


Question


<?php
$json = file_get_contents("http://twitter.com/status/user_timeline/USERNAME.json?count=10", true);
$decode = json_decode($json, true);
$count = count($decode); //counting the number of status
echo "<img src=\"".$decode[0][user][profile_image_url]."\"</img><br>"; //getting the profile image
echo "Name: ".$decode[0][user][name]."<br>"; //getting the username
echo "Web: ".$decode[0][user][url]."<br>"; //getting the web site address
echo "Location: ".$decode[0][user][location]."<br>"; //user location
echo "Updates: ".$decode[0][user][statuses_count]."<br>"; //number of updates
echo "Follower: ".$decode[0][user][followers_count]."<br>"; //number of followers
echo "Following: ".$decode[0][user][friends_count]."<br>"; // following
echo "Description: ".$decode[0][user][description]."<br>"; //user description
echo "TimeZone: ".$decode[0][user][time_zone]."<br>"; //Timezone
echo "<br><br>";
for($i=0;$i<$count;$i++){
echo "Status: ".$decode[$i][text]."<br>"; //getting last 10 statuses}
}
?>
[/CODE]

This snippet will grab the particular users info from twitter along with the last 10 status

just change USERNAME to your twitter username

any questions let me know :)

19 answers to this question

Recommended Posts

  • 0

Can you do one that embeds a tweet in a forum post to achieve what is requested here? http://www.neowin.ne...5-embed-tweets/

I can add php to bbcode replacement but not Javacript, although I can add the widget.js to our board header. https://dev.twitter....embedded-tweets

Edit: Redmak is also working on this :p

  • 0

if you add the widget.js to your board header

this is the html replace for the bbcode



<blockquote class="twitter-tweet"><p>Javascript is not enabled</p><a

href="https://twitter.com/twitterapi/status/237131910013394944">Click here to view the Tweet</a></blockquote>[/CODE]

so would just be the tweet id needing replaced

I will look more when i get home, let me know if this is useful though :)

  • 0

so

[tweet]237131910013394944[/tweet][/CODE]

[CODE]
<blockquote class="twitter-tweet"><p>Javascript is not enabled</p><a

href="https://twitter.com/twitterapi/status/{content}">Click here to view the Tweet</a></blockquote>[/CODE]

if this is not what you mean i can make a bit of code to pull the particular tweet then you could just add some niceness to the display lol

  • 0

damn, I knew it was as easy as this! I'll give it a try, thanks.. I was getting a bit confused with the "content" switch lol

Hmm does that post a link, or the embedded tweet?

It friggin works!

Different tweet test

  • 0

Cool glad it works :)

Thanks, I've modified it so the whole URL can be pasted in (easier to remember for everyone)

Example:

[tweet]https://twitter.com/NeowinSteve/statuses/237116811357859841[/tweet]

Replacement:

&lt;blockquote class="twitter-tweet"&gt;&lt;p&gt;Javascript is not enabled&lt;/p&gt;&lt;a

href="{content}"&gt;Click here to view the Tweet&lt;/a&gt;&lt;/blockquote&gt;

Thanks for your help on this :)

  • 0

No probs at all :) as i say glad i could help

It doesn't load with fast reply, but youtube videos do, do you reckon there's a way around this?

Could it be the Javascript notice that stops it loading?

  • 0
  • 0

Hmm I suppose it calls the javascrtipt in our header to render the tweet?

&lt;script src="//platform.twitter.com/widgets.js" charset="utf-8"&gt;&lt;/script&gt;

which is only parsed with a page refresh. I don't see a way around this lol

  • 0

yeah looking at the ipb site the javascript wont parse in a fast reply so the bbcode wont work

its should work once the page is refreshed so will only not work for you once the post is submitted

Javascript is not enabled or refresh the page to view.

Click here to view the Tweet
  • 0

modify the post button to get it working with fast reply without a page reload:

<input type="submit" id="submit_post" class="input_submit" name="submit" value="post" acceskey="s" tabindex="0" onclick="tweet();">Post</input>[/CODE]

[CODE]
<script>
function tweet {
if #submit_post content contains the following text "[tweet]" { *idk code to lookup text in a element :p*
*tweet code*
}
</script>
[/CODE]

  • 0

modify the post button to get it working with fast reply without a page reload:

<input type="submit" id="submit_post" class="input_submit" name="submit" value="post" acceskey="s" tabindex="0" onclick="tweet();">Post</input>[/CODE]

[CODE]
<script>
function tweet {
if #submit_post content contains the following text "[tweet]" { *idk code to lookup text in a element :p*
*tweet code*
}
</script>
[/CODE]

That didn't work, oh well :p

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Audacious 4.6.1 by Razvan Serea Audacious is a lightweight, open-source audio player that emphasizes simplicity, performance, and sound quality. Designed for Linux, Windows, and macOS, it supports a wide range of audio formats, internet radio streaming, and playlist management. Users can customize the interface with Winamp-style skins or modern themes, making it flexible for different preferences. Audacious also includes an equalizer, advanced audio effects, and a plugin system for extending functionality. Its low resource usage makes it especially suitable for older computers or users who value efficiency without sacrificing playback quality. Audacious key features: High audio quality – delivers clean, gapless playback with minimal distortion. Wide format support – plays MP3, FLAC, Ogg Vorbis, AAC, WAV, WMA, and more. Internet radio streaming – supports Shoutcast, Icecast, and other online streams. Winamp skin support – classic, nostalgic look for users who prefer the old-school style. Modern GTK-based interface – clean, simple UI with a more modern feel. Customizable themes – change appearance through skins and themes. Advanced playlist management – organize, save, and edit playlists with ease. Equalizer – fine-tune audio output with a built-in graphical equalizer. Audio effects – built-in DSP options like crossfade, replay gain, and more. Plugin system – extend functionality with additional components. File metadata support – displays and organizes music based on tags. Drag-and-drop support – quickly add songs or playlists. Global hotkey support – control playback without switching windows. Bit-perfect output modes – bypass system mixers for pure audio output. ReplayGain support – normalizes track loudness automatically. Cue sheet support – play entire albums from a single audio file with .cue. MPRIS2 integration – integrates with Linux desktop environments for media controls. Advanced resampling options – adjust playback quality with different resampler settings. Gapless playback – seamless transition between tracks encoded properly. Crossfade plugin – blend one song into the next smoothly. Last.fm scrobbling plugin – track listening history online. Remote control support – control Audacious via command-line or scripts. Lyrics plugin – display song lyrics if available. Alarm / timer plugin – start or stop playback at set times. SOX resampler plugin – high-quality resampling for audiophiles. Spectrum analyzer / visualization plugins – visual feedback while playing music. Headphone crossfeed effect – simulates speaker listening for headphones. Customizable buffer size – tweak latency and playback smoothness. Audacious 4.6.1 changelog: Use XDG cache dir to store temporary files (#1817) Accept embedded lyrics in more cases (#1818) Bump .so and plugin ABI versions retrospectively (#1819) Include Georgian translation (#1820) Fix build on systems using musl instead of glibc (#1823) Download: Audacious 4.6.1 | 48.2 MB (Open Source) Download: Portable Audacious 4.6.1 | 69.8 MB View: Audacious Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • I really wonder if this has to do with the built in VPN or "private DNS" of browsers that trip up legal requirements like cookie consent and Cloudflare (to avoid all the botnet attacks we get). And BTW some botnets still manage to get past Cloudflare, we are constantly having to tweak it to block malicious traffic that ultimately cause a DDoS.
    • CPPC states can also be messed around with in most UEFI settings but aren't as robust as the ones that the Windows Scheduler can provide! Make sure you look into what your motherboard also has before customizing for the Windows Scheduler.
  • Recent Achievements

    • Week One Done
      rolfus earned a badge
      Week One Done
    • One Month Later
      Leroy Jethro Gibbs earned a badge
      One Month Later
    • Conversation Starter
      flexorcist earned a badge
      Conversation Starter
    • One Month Later
      AndreaB earned a badge
      One Month Later
    • One Month Later
      agatameier earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      518
    2. 2
      +Edouard
      198
    3. 3
      PsYcHoKiLLa
      147
    4. 4
      ATLien_0
      93
    5. 5
      Steven P.
      78
  • Tell a friend

    Love Neowin? Tell a friend!