首页 > 解决方案 > Twitter API - 显示多个指定用户的最新推文

问题描述

我想知道是否可以显示我指定的多个 Twitter 用户的最新推文。

这就是我删除键后的结果,它们确实在我的实际代码中定义

<?php
require_once('TwitterAPIExchange.php');

$settings = array(
    'oauth_access_token' => "",
    'oauth_access_token_secret' => "",
    'consumer_key' => "",
    'consumer_secret' => ""
);

$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?user_id=McDonalds,Wendys,Dominos&count=1';
$requestMethod = 'GET';

$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();

echo '<pre>';
$response = var_dump(json_decode($response));

但它只输出我最新的推文。我怎样才能使它输出指定用户的最新推文?

标签: phpapitwitter

解决方案


有两种方法可以做到这一点 - 都不是你想要的那么简单。

首先,您可以单独为每个用户请求用户时间线。

所以打电话https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=McDonalds,然后https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=Wendys等等。

那可能很慢。因此,或者,您可以创建一个包含所有要关注的用户的列表。

然后,您可以使用 List API获取这些用户的所有最新推文。


推荐阅读