Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get user media (photos) only - Twitter API

Tags:

php

twitter

Using the Twitter API V1.1 is it possible to just retrieve the photos that a user has posted?

I can see that one way to do this is to pull a user's timeline with include_entities=true and search for the photos that way. But that seems like an extremely cumbersome way around, and prone to problems.

For example, we can pull the last 15 tweets and display them, and we know, for sure, that we will always get 15 tweets.

But for just photos, if we were to even pull 100 tweets at a time, we can not be guaranteed that it will contain, say, 15 photos, or even that it will contain any photos at all.

So perhaps I'm clutching at straws here hoping that there is some way to do this that the Twitter API docs and Dev Discussions doesn't know.

I'm looking for a PHP example.

like image 262
nerdarama Avatar asked Aug 08 '13 14:08

nerdarama


People also ask

How do I see only photos on Twitter?

Once the feed is displayed in the main window, you need to set it up so that it only shows images. Hit the filter icon in the top-right corner of the feed, then expand the Tweet content menu. From there, you need to select Tweets with images in the Showing dropdown menu.

How do you get Twitter media?

How do I access Media Studio? To access Media Studio, go to studio.twitter.com and log in using your Twitter credentials. You can also go to Twitter.com, click on the More button within the side menu and then click on the Media Studio button.

How do I see all Twitter media?

Visit any Twitter profile and you should see the “View all photo and videos” link below the most recent six images/videos that the user has tweeted […]


1 Answers

This might be helpful: Get Tweets with Pictures using twitter search api

I did a little research and it's possible to get tweets containing only photos, but I am not sure if it shows all tweets photos posted by user.

Example with using Twitter-php

require_once 'Twitter-php/RestApi.php';

$consumerKey = 'YOUR CONSUMER KEY';
$consumerSecret = 'YOUR CONSUMER SECRET';
$accessToken = 'YOUR ACCESS TOKEN';
$accessTokenSecret = 'YOUR ACCESS TOKEN SECRET';

$twitter = new \TwitterPhp\RestApi($consumerKey,$consumerSecret,$accessToken,$accessTokenSecret);
$connection = $twitter->connectAsApplication();
$tweets = $connection->get('search/tweets', array('q'=>'from:nasa filter:images','include_entities'=>1));

This example code should return NASA tweets containing images.

like image 112
Albert Kozłowski Avatar answered Oct 19 '22 23:10

Albert Kozłowski