Register Twitter Webhook API

webhooks

#1

I’m new to twitter webhook API. Unable to register webhook API.

Not getting what to send as param to “https://api.twitter.com/1.1/account_activity/webhooks.json” url, to register webhook api.

Please help me with proper documentation.


#2

https://dev.twitter.com/webhooks/reference/post/account_activity/webhooks

Pass in an encoded URL where you want to receive the webhook callbacks that meets the requirements documented in the Getting Started and Securing Webhooks pages.


#3

HI, Thanks for the reply.

My problem yet not solved. I’m tring to register using PHP. Here is the code.

function getParamas(){
$params = array(
‘oauth_consumer_key’ => ‘Consumer Key (API Key)’,
‘oauth_signature_method’ => ‘HMAC-SHA1’,
‘oauth_timestamp’ => time(),
‘oauth_nonce’ => time(),
‘url’ => ‘base64 encoded Callback URL’
);

$post_string = '';
foreach($params as $key => $value)
{
    $post_string .= $key.'='.($value).'&';
}
$post_string = rtrim($post_string, '&');
$base_string = rawurlencode($post_string);
$signature = base64_encode(hash_hmac('sha1', $base_string, 'Consumer Secret (API Secret)', true));
$params['oauth_signature'] = $signature;

return $params;

}

$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => “https://api.twitter.com/1.1/account_activity/webhooks.json”,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => getParamas(),
);

curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);

This throws {“errors”:[{“code”:215,“message”:“Bad Authentication data.”}]} error. Not getting where I’m going wrong.


#4

I tried “TwitterAPIExchange.php”

$settings = array(
‘oauth_access_token’ => ‘my_oauth_access_token’,
‘oauth_access_token_secret’ => ‘my_oauth_access_token_secret’,
‘consumer_key’ => ‘my_consumer_key’,
‘consumer_secret’ => ‘my_consumer_secret’
);

$url = ‘https://api.twitter.com/1.1/account_activity/webhooks.json’;

$requestMethod = ‘POST’;
$postfields = array(
‘url’ => ‘Encoded URL’
);

$twitter = new TwitterAPIExchange($settings);

echo $twitter->setPostfields($postfields)
->buildOauth($url, $requestMethod)
->performRequest();

This throws error = {“errors”:[{“code”:87,“message”:“Client is not permitted to perform this action.”}]}

but if I use url = [“https://api.twitter.com/1.1/account_activity/webhooks.json?allow_dms_from=all not anyone”] I’m not getting any Messages


But with the same settings I tried search api, and it is working as expected.

> $url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=ResolvHelp&include_entities=0';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);

echo $twitter->setGetfield($getfield)
        ->buildOauth($url, $requestMethod)
        ->performRequest();