Hi since moving to API 1.1 I keep getting the following error message when I try to get a list of my followers.
{“errors”:[{“message”:“Bad Authentication data”,“code”:215}]}
Basically the script is using the same Twitter / oAuth classes as most Wordpress plugins do (including my own) and I have changed line 29 in the Twitter class to:
/* Set up the API root URL. */
public $host = “https://api.twitter.com/1.1/”;
Which resolved the issue in my own WordPress plugins. However I just cannot seem to get a list of my followers back even if I can send tweets out.
My scripts are run from CRON jobs and I connect to Twitter with my application consumer key/secret and access key/secret and the authentication message comes back that I am logged in.
I then try and access the URL that should return your followers in the new Twitter 1.1 API e.g
https://api.twitter.com/1.1/followers/list.json?screen_name=mytwitteraccount
However even though I am logged in I cannot get a response.
I am using the inbuilt Twitter method http which uses CURL and passes your consumer / access keys and secrets along with all requests.
$response =$oauth->http(“https://api.twitter.com/1.1/followers/list.json?screen_name=mytwitteraccount","GET”);
However even though the oauth class is telling me that the credentials for my screen name are valid, when I try to make a GET request to get the JSON for my followers list I get back the Bad Authentication 215 error message:
The full code is below:
// a simple debug statement echo/print_r
ShowDebug("load twitter");
// include the twitter class which also includes the oauth class
require_once(‘twitter.class.php’ );
ShowDebug(“loaded twitter class”);
// Twitter settings - these are fake so don’t try and use them!
$consumersecret = “ghweweLGhQxA2zGiHrUFW6X8HTdsJPOrau0fw24veUU”;
$consumerkey = “1pRwT3gNcmmnLKnrp9g”;
$accessToken = “112534562-Jj5QLN7XpRNgKjHi289DvBWDrmt1jxX2Wink5tTvbRe”;
$accessTokenSecret = “lbXdFtGttkjEGpmgGqsAACftLfseCvemxfNPKrCeTmENtUOk”;
ShowDebug("connect with access token = " . $accessToken . " and secret = " . $accessTokenSecret);
// pass my keys
$oauth = new TwitterOAuth($consumerkey, $consumersecret, $accessToken, $accessTokenSecret);
ShowDebug(“VERIFY ACCOUNT WITH OAUTH”);
// Send an API request to verify credentials
$credentials = $oauth->get(“account/verify_credentials”);
// a print_r shows me all my details here - so I am verified!
print_r($credentials);
// so I should be logged in now
if(!empty($credentials->screen_name))
{
ShowDebug( “Connected as @” . $credentials->screen_name);
ShowDebug("check for new followers");
$followers_url = "https://api.twitter.com/1.1/followers/list.json?screen_name=myscreenname";
$response = $oauth->http($followers_url,"GET");
ShowDebug($response);
ShowDebug("status is " . $oauth->http_code);
}
And the debug I get back is the following:
load twitter
load oauth
do class
OAuthToken loaded
loaded twitter class
connect with access token = 112534562-Jj5QLN7XpRNgKjHi289DvBWDrmt1jxX2Wink5tTvbRe and secret = lbXdFtGttkjEGpmgGqsAACftLfseCvemxfNPKrCeTmENtUOk
VERIFY ACCOUNT WITH OAUTH
Connected as @MyTwitterAccount
check for new followers
{“errors”:[{“message”:“Bad Authentication data”,“code”:215}]}
status is 400
If anyone can help me then please let me have your knowledge! Twitter so far haven’t helped at all.
And before anyone asks
Yes I have an application set up for my Twitter account to carry out these requests.
Yes I have double checked my consumer and access keys.
The URL to get the follower list was copied direct from the twitter developer site.
Also if instead of trying to get a list of followers back I run this code instead
$replymsg = "a test message";
$res = $oauth->post(
'statuses/update',
array(
'status' => $replymsg,
'source' => 'Strictly Tweetbot'
)
);
if(isset($res->error) && !empty($res->error)){
ShowDebug("An error occurred posting $replymsg to $name - " . $res->error);
}else{
ShowDebug("TWEET SENT OK");
$success = true;
}
I can send a tweet. Therefore I am authenticated properly.
Any help would be much appreciated!