Twitter API returning Error: 34 (404)

2019-07-25 01:21发布

问题:

I am trying to returning trending topics in the USA from the twitter API using TwitterAuth0 however I am getting, {"errors":[{"message":"Sorry, that page does not exist","code":34}]} as a result. My code is as following:

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

My actual credentials are in the keys/secrets, currently my callback url on twitter apps is the page of the feed I am returning, is this correct? (So the acutal page to see the feed)

Any help on this error is appreciated.

回答1:

Figured out the issue:

Get piece needed to be:

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

instead of:

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