I need to check if the twitter name user puts to the form exists or not.
I am using TwitterOAuth by Abraham Williams to do that, but I always get just false...
Here is the code:
require_once 'includes/twitteroauth/autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
define('CONSUMER_KEY', ' ');
define('CONSUMER_SECRET', '');
define('ACCESS_TOKEN', '');
define('ACCESS_TOKEN_SECRET', '');
function find_users(array $users){
$founds = array();
$toa = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
// Up to 100 users per request.
$userAry = array_slice($users, 0, 100);
// Init with "not found" for all users.
foreach ($userAry as $user) {
$founds[$user] = false;
}
// Find existing users by "screen_name".
$userObjs= $toa->post('users/lookup', array('screen_name' => implode(',', $userAry)));
// Set "found" for existing users.
foreach ($userObjs as $userObj) {
$founds[$userObj->screen_name] = true;
}
return $founds;
}
Here is my call (I put there some names I know exist and also their register names, just to be sure):
if ($pass AND !empty($twitter)){
$twitter_array = array($twitter, "Jayztwocents", "Barnacules", "Barnacules Nerdgasm", "Inu-ki", "Inukii", "HiRezStew", "schisam", "twitter", "twitterapi");
$check_twitter = find_users($twitter_array);
var_dump($check_twitter);
die;
if (!$check_twitter[0]){
$message .= "<li>This twitter account does not exist.</li>"; $pass = FALSE; $twitter_class = "required";
}
}
This is the result of my var_dump:
array(11) {
["MiChAeLoKGB"]=> bool(false)
["Jayztwocents"]=> bool(false)
["Barnacules"]=> bool(false)
["Barnacules Nerdgasm"]=> bool(false)
["Inu-ki"]=> bool(false)
["Inukii"]=> bool(false)
["HiRezStew"]=> bool(false)
["schisam"]=> bool(false)
["twitter"]=> bool(false)
["twitterapi"]=> bool(false)
[""]=> bool(true)
}
Why does it always return false, and why the heck is as the end emty string thats true?
Ps.: All the keys/secrets are correctly set up.
PPs.: I googled a lot and there are questions about it on this site, but they all use old API which is disabled.