【发布时间】:2017-02-10 16:37:59
【问题描述】:
我想通过 Twitter API 检索关注某个其他用户(例如 @Google)的用户的所有 Twitter ID。虽然该请求在 Postman 中有效,但我无法使其在 PHP 中有效。看来 $userids 不是字符串,所以 json_decode 无法处理。代码如下。感谢您的帮助!
<?php
require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
ini_set('max_execution_time', 600);
ini_set('memory_limit', '1024M');
$consumerKey = 'redacted';
$consumerKeySecret = 'redacted';
$accessToken = 'redacted';
$accessTokenSecret = 'redacted';
$cursor = -1; // first page
$connection = new TwitterOAuth($consumerKey, $consumerKeySecret, $accessToken, $accessTokenSecret);
$content = $connection->get("account/verify_credentials");
$userids = $connection->get("followers/ids", ["cursor" => -1, "screen_name" => "google", "count" => 5000]);
echo $userids;
$data = json_decode($userids);
foreach ($data as $ids => $value) {
// tbd
}
var_dump($data);
?>
【问题讨论】:
-
那么代码的实际行为是什么? “看来
$userids不是字符串” - 你能检查一下吗?