Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Twitter API返回错误:34(404)_Php_Json_Rest_Api_Twitter - Fatal编程技术网

Php Twitter API返回错误:34(404)

Php Twitter API返回错误:34(404),php,json,rest,api,twitter,Php,Json,Rest,Api,Twitter,我正在尝试使用TwitterAuth0从twitter API返回美国的趋势主题,但结果是,{“errors”:[{“message”:“抱歉,该页面不存在”,“code”:34}]}。我的代码如下: session_start(); require_once("twitteroauth-master/autoload.php"); //Path to twitteroauth library use Abraham\TwitterOAuth\TwitterOAuth; $id = "2342

我正在尝试使用TwitterAuth0从twitter API返回美国的趋势主题,但结果是,
{“errors”:[{“message”:“抱歉,该页面不存在”,“code”:34}]}
。我的代码如下:

session_start();
require_once("twitteroauth-master/autoload.php"); //Path to twitteroauth library
use Abraham\TwitterOAuth\TwitterOAuth;

$id = "23424977";
$consumerkey = "XXX";
$consumersecret = "XXX";
$accesstoken = "XXX";
$accesstokensecret = "XXX";

function getToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
    $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
    return $connection;
}

$connection = getToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);

$tweets = $connection->get("https://api.twitter.com/1.1/trends/place.json?id=".$id);
echo json_encode($tweets);
我的实际凭证在keys/secrets中,当前我在twitter应用程序上的回调url是我返回的提要页面,是否正确?(因此,请访问acutal页面以查看提要)

非常感谢您对此错误提供的任何帮助。

解决了问题:

获取所需的工件:

$tweets = $connection->get("trends/place", [ "id" => 23424977 ]);
而不是:

$tweets = $connection->get("https://api.twitter.com/1.1/trends/place.json?id=".$id);
解决了这个问题:

获取所需的工件:

$tweets = $connection->get("trends/place", [ "id" => 23424977 ]);
而不是:

$tweets = $connection->get("https://api.twitter.com/1.1/trends/place.json?id=".$id);