Delete Welcome Message / Add Subscription to webhook

api
webhooks
account-activity

#1

Hi everyone,

i have access to the “Standard beta Account Activity API”.
I would like to create a subscription to a webhook, but i can’to do it.
My webhook is created, but when i want to create a subscription to this webhook calling the url
"https://api.twitter.com/1.1/account_activity/all/env-beta/webhooks/WEBHOOK_ID/subscriptions.json"

i have the error :

{“errors”:[{“message”:“Sorry, that page does not exist”,“code”:34}]}

Could you hep me.

Thanks


#2

The correct URL is https://api.twitter.com/1.1/account_activity/all/env-beta/subscriptions.json

You don’t need to provide the webhook_id in the path.


#3

Thank you, i finally found that :slightly_smiling_face:

Now i am facing another problem, when i send a message through the twitter page, i don’t receive anything in my webhook url defined.

Any Idea ?

Thanks


#4

Are you sure the subscription was successfully created?

If yes, then depending of your setup, I will first check the logs (apache, nginx…) if any HTTP error is raised when you should receive something from Twitter Webhooks.


#5

It is based on NodeJs.
I use this boilerplate : https://github.com/twitterdev/twitter-webhook-boilerplate-node

I receive this log when i send a message on Twitter :

“at=info method=POST path=”/webhooks/twitter" host=twitterbotmaniacom.herokuapp.com request_id=19726b2f-704e-4236-b4e6-7222c4ef30ae fwd=“199.16.157.172” dyno=web.1 connect=0ms service=6ms status=404 bytes=228 protocol=https"

but i can’t log the request in the console.


#6

“at=info method=POST path=”/webhooks/twitter" host=twitterbotmaniacom.herokuapp.com request_id=19726b2f-704e-4236-b4e6-7222c4ef30ae fwd=“199.16.157.172” dyno=web.1 connect=0ms service=6ms status=404 bytes=228 protocol=https"

The web hook URL you provided is not correct and Twitter can’t send datas to it.


#7

Hi everybody,

i decided to make it with php, so i call the webservice account_activity/all/env-beta/webhooks, but it return me the error :

(int) 0 => object(stdClass) {
			code => (int) 214
			message => 'Webhook URL does not meet the requirements. Invalid CRC token or json response format.'
		}

I put you my code behind this url :

if (isset($query['crc_token'])) {
            
            $token = trim($query['crc_token']);
            $consumerKey = trim($entry->page->twitter_consumer_secret);
            $sha256_hash_digest = hash_hmac('sha256', $token, $consumerKey);
            
            $result = json_encode([
                'response_token' => "sha256=".base64_encode($sha256_hash_digest)
            ]);
            
            return $this->response->withType('application/json')->withStringBody($result)->withStatus(200)->withCharset("UTF-8");
        }

Thanks for your help.


#8

Here is the CRC token function I use on my app:

public function getChallengeResponse(string $token) : string
    {
        $hash = hash_hmac('sha256', $token, TWITTER_CONSUMER_SECRET, true);
        $response = ['response_token' => 'sha256=' . base64_encode($hash)];
        return json_encode($response);
    }

And on top of my webhooks page, something like:

if (isset($_GET['crc_token'])) {
    echo $webhook->getChallengeResponse($_GET['crc_token']);
    exit;
}

#9

It works, i send you thousands thanks !