How to register webhook url

restapi
php
webhooks
account-activity

#1

I am trying to register a webhook url to receive events. But I am getting an error in response as below:

{
    "errors": [
        {
            "code": 261,
            "message": "Application cannot perform write actions. Contact Twitter Platform Operations through https://support.twitter.com/forms/platform."
        }
    ]
}

I am using application only authentication to perform OAuth2. I am using php for this.
What can be the issue here?


#2

@vinodsaini could you send your request header?


#3

@R_Amsaveni Thanks for the reply.

I am using below code ;


$url =  urlencode('https://tweester.in/tweetcafe/webhook/twitter/getTweet.php');
$webhooksUrl = 'https://api.twitter.com/1.1/account_activity/all/env-beta/webhooks.json?url=' . $url;
$token = 'my_access_token';
$headers = array(
	'Content-Type:application/x-www-form-urlencoded',	
	'authorization: Bearer ' . $token,
);
$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);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
$result  = curl_exec($ch); 
curl_close($ch); 
echo '<pre>';print_r($result);exit;

#4

Have you encoded your access token using base64 encoder?


#5

Yes, I have created bearer token using base24 encode. See below code to generate access token;

$encodedBearerTokenCredentials = base64_encode($consumer_key . ':' . $consumer_secret);
$authUrl = 'https://api.twitter.com/oauth2/token/?grant_type=client_credentials';
$headers = array(
	'Content-Type: application/x-www-form-urlencoded;charset=UTF-8',
	'Authorization: Basic ' .  $encodedBearerTokenCredentials,
);

And post this using curl method.


#6

https://developer.twitter.com/en/docs/basics/authentication/overview/application-only

The above link will explain how to generate bearer token. It says to use base64 encoder.

why don’t you try this one

sorry if I’m wrong :slightly_frowning_face:


#7

@Amsa I used the same link to generate bearer token already. But its showing same error.

Above link doing base64_encode($consumer_key . ':' . $consumer_secret);