0

I'm trying to create a collage of images that are sourced from a twitter feed to be displayed in a website banner.

So far I have set up the Twitter authentication

I'm not sure how to go about extracting just the images from her feed, or embed them in the desired manner.

Any help or information would be greatly appreciated.

Click here to view a possible outcome I'm looking for.

Thanks!

  • Cool cool! So you're already able to get the tweets? Consider just getting a bunch of tweets, and seeing what data is there (especially for image posts), and what the structure of the data is. Post some sample data here if possible, and we'll help work out a way of extracting it. – Luke May 19 '15 at 04:30
  • @Luke Yep the tweets come through as a huge jumble of json data (I think?). I modified the query with a search function I found. http://stackoverflow.com/questions/13920851/get-tweets-with-pictures-using-twitter-search-api php: http://pastebin.com/eEahVJhE Here is the output: http://pastebin.com/zrNG3hwn – Dougie Mason May 19 '15 at 05:21
  • Okay, I copied the JSON into a JSON formatter to make it readable, worked my way through the data... `foreach ($result->statuses as $status) { echo $status->entities->media[0]->media_url }` If that looks useful, I'll make an answer? – Luke May 19 '15 at 05:43
  • looking good! Am I correct in saying this extracts the URL for each image into an array? How then do we go about wrapping image tags? Cheers @Luke – Dougie Mason May 19 '15 at 06:16
  • ``? Come on, you obviously know how to PHP :) – Luke May 19 '15 at 06:17
  • Or am I missing something? Perhaps be more specific on how you're wanting to embed them? Can't we just dump a whole lot of image elements into the page somewhere? – Luke May 19 '15 at 06:17
  • My PHP skills are pretty basic; I can modify existing layouts and functions, but writing from scratch isn't really up to par yet. Yes; I planned on inserting the last 5-10 images and styling it. @Luke – Dougie Mason May 19 '15 at 06:37

1 Answers1

0

To simply dump a couple of images, try this:

<?php

require_once("/twitteroauth/twitteroauth.php");

$consumerKey = "0LQwV6gQi1hi8TPOMvfqy7qpM";
$consumerSecret = "AuShkWcg7lj8VYyKYOH6WPW8tY6B2QuB8kgRpmALVrg0VK0mM0";
$accessToken = "624631261-DjWeq4RB0eGAB2lr68skZE1zbfDcg2x6BEyJzFZO";
$accessTokenSecret = "8XnWnkiFQ803r9sHVkDrZNhD50EuJlnw8sZI2EPsA9p7X";
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
$tweets = $connection->get("https://api.twitter.com/1.1/search/tweets.json?q=%rhyareegaming%20filter%3Aimages&include_entities=true");
foreach ($tweets->statuses as $status) {
?>
    <img src="<?php echo $status->entities->media[0]->media_url; ?>">
<?php
}
Luke
  • 1,724
  • 1
  • 12
  • 17
  • If you need help with putting the images in the right place, let me know? :) – Luke May 19 '15 at 06:47
  • PERFECT! nifty trick with the variables in an image source. Didn't know you could do that. Cheers Luke! I'll see how I go with the styling, will reply if I have any troubles. :D – Dougie Mason May 19 '15 at 06:47
  • :) So that's how you'll usually mix PHP and HTML. Try and keep them separate where possible, and echo the absolute minimum. See how I'm only echoing the dynamic part (the URL), whereas the rest of the element is OUTSIDE the – Luke May 19 '15 at 06:49