Authentication problem when registering webhook



Hi guys! Im new here :slight_smile:
I am also rather new regarding developing in general.

I’m trying to register a webhook to listen on account activity (my own twitter timeline), but when I run the script register-webhook-script I get the following error:
“{“errors”:[{“code”:32,“message”:“Could not authenticate you.”}]}”

I would greatly appreciate any advice on what might be wrong! Might be I’ve missed something obvious :slight_smile:

Below is the script code. I have put it toghether by following the guidelines in: &

//keys and tokens

//generate url
$url = ''; //url for listening script
$twitter_url = '';
$webhooksurl = $twitter_url;

//generate nonce
function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
    $pieces = [];
    $max = mb_strlen($keyspace, '8bit') - 1;
    for ($i = 0; $i < $length; ++$i) {
        $pieces []= $keyspace[random_int(0, $max)];
    return implode('', $pieces);
$nonce=preg_replace("/[^A-Za-z0-9 ]/", '', $b64); //strip all alfanumeric

//genereate timestamp

//generate oauth_signature
$ps='';  //parameter string, part of oauth signature string
$ps.=rawurlencode('true'); //unsure on this one
//----- unsure if below should be included since its not a status update. have tried not including it.

//signature_base_string, part of oauth signature string

//signing key, part of oauth signature string

$oauth_signature=base64_encode($oauth_signature); //oauth signature string

//header string
$dst.='OAuth ';
$dst.='", ';
$dst.='", ';
$dst.='", ';
$dst.='", ';
$dst.='", ';
$dst.='", ';

$headers = array(
	'content-type: application/x-www-form-urlencoded',	
	'authorization: '.$dst

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $webhooksurl); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
$result  = curl_exec($ch); 

echo '<pre>';print_r($result);exit;


Can you double check your authentication? Are you able to use this authentication to make other calls on your own account, other than registering a webhook?


We also have a troubleshooting guide for this error message and API here:


Hi! Sorry for my late reply.
I haven’t used this particular script for other purposes, but I have successfully used my twitter keys/tokens in a test script where I read posts on my home_timeline:

//include library
require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;

//connect to api
$connection=new TwitterOAuth($consumer_key,$consumer_secret,$access_token,$access_token_secret);

… so at least there’s nothing wrong with my tokens.

I suspect the problem might lie somewhere in the header string generation. Maybe in the $ps string. I’m not sure I use correct settings there.

Is there no easy way to do this? For example, I read someone had registered a webhook using the TwitterOAuth library. If someone could point the way how to do something like that I’d be grateful!

Thank you for your time!


Thanks, have looked there to no avail.


We have updated our troubleshooting documentation for error 32. Please read through this again and make sure that you are using both the proper tokens from your Twitter app that you’ve added to your dev environments page, as well as generate the proper oauth nonce , oauth_signature , and oauth_timestamp tokens.