Search code examples
phptwittertwitter-oauth

Twitter API - Get Statuses not Finding Any User Page


The title pretty much sums it up: I can't find any pages using Get Statuses with the Twitter API.

Here's my code.

<?php
session_start();
require "abraham/twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;

$twitteruser = "IliaVED"; //User name I'm looking for
$id = "486654831"; //Corresponding id
$notweets = 30; //how many tweets you want to retrieve

$consumerkey = "xxx"; 
$consumersecret = "xxx";      
$accesstoken = "xxx"; 
$accesstokensecret = "xxx"; 

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

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

$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);

echo json_encode($tweets);
echo $tweets;   
?>

I tried using the ID instead of the screen name and it still doesn't find it.

You can clearly see that the user exists:https://twitter.com/IliaVED

I tried with different users and it does the same thing..

This is the error I get:

{"errors":[{"message":"Sorry, that page does not exist","code":34}]}

Solution

  • You're missing = after screen_name in URL GET parameters part. Use:

    $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $twitteruser . "&count=".$notweets);
    

    EDIT: Actually, you are using the library in wrong way, try with:

    $tweets = $connection->get("statuses/user_timeline", ["screen_name" => $twitteruser, "count" => $notweets]);
    

    Library itself has base URL and adds it to the path you provide and handles array of URL GET parameters.