本文介绍了仅获取用户媒体(照片) - Twitter API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Twitter API V1.1 是否可以只检索用户发布的照片​​?

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

我可以看到一种方法是使用 include_entities=true 拉出用户的时间线,然后以这种方式搜索照片.但这似乎是一种极其麻烦的方法,并且容易出现问题.

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.

例如,我们可以拉取最后 15 条推文并显示它们,而且我们可以肯定地知道,我们总是会收到 15 条推文.

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

但对于照片而言,如果我们一次拉 100 条推文,我们不能保证它会包含 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.

所以也许我在这里抓着稻草希望有某种方法可以做到这一点 Twitter API 文档Dev Discussions 不知道.

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.

我正在寻找一个 PHP 示例.

I'm looking for a PHP example.

推荐答案

这可能会有帮助:使用推特搜索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.

使用 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));

此示例代码应返回包含图像的 NASA 推文.

This example code should return NASA tweets containing images.

这篇关于仅获取用户媒体(照片) - Twitter API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 11:26