简体   繁体   English

仅获取用户媒体(照片) - Twitter API

[英]Get user media (photos) only - Twitter API

Using the Twitter API V1.1 is it possible to just retrieve the photos that a user has posted? 使用Twitter API V1.1是否可以只检索用户发布的照片​​?

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. 我可以看到,实现此目的的一种方法是使用include_entities=true拉出用户的时间轴并以这种方式搜索照片。 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. 例如,我们可以提取最后15条推文并显示它们,我们知道,我们肯定会得到15条推文。

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. 但是对于刚刚拍摄的照片,如果我们一次只推送100条推文,我们无法保证它会包含15张照片,甚至根本不包含任何照片。

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. 所以也许我正抓着这里的稻草,希望有一些方法可以做到这一点, Twitter API文档开发者讨论不知道。

I'm looking for a PHP example. 我正在寻找一个PHP示例。

This might be helpful : Get Tweets with Pictures using twitter search api 这可能会有所帮助使用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 使用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. 此示例代码应返回包含图像的NASA推文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM