super-ienien / twitter-webhooks

Easy to use expressJs middleware for twitter webhooks api
MIT License
20 stars 3 forks source link

Sorry, this page doesn't exist + You must provide a webhookid #8

Closed jokoast closed 4 years ago

jokoast commented 5 years ago

Hi, you would maybe be able to help me understand some things of the API.

I've a premium (free) AAA environ nement, i registered a webhook but since i used ngrok, the serverurl changed so i had the error :

Sorry, this page doesn't exist

So i tried to remove my webhook (and create it back) and I got this error when i try to remove it :

UnhandledPromiseRejectionWarning: Error: You must provide a webhookId

Using :

userActivityWebhook.getWebhooks()
.then((webhooks) => {
    userActivityWebhook.unregister(env + "/webhooks/" + webhooks.environments[0].webhooks.id)
    .then((response) => {
        console.log(response);
    });
});

or just :

userActivityWebhook.unregister(webhooks.environments[0].webhooks.id)

I wanted a way to "kill" my webhook at every start because i use ngrok (free) and my serverURL changes sometimes.

Thank you

super-ienien commented 5 years ago

Hello,

Sorry for this very late response. I understand your issue because I had the same. To kill a webhook registration you need it's id. You cannot kill webhooks without id. I made a request to twitter in order they implement a way to kill webhooks with it's url instead of it's id : https://twittercommunity.com/t/account-activity-delete-subscription/110634

So ! If you wan't to unregister your webhook at each start. You first need to query your webhooks list to twitter's API. You can use the getWebhooks() method of this package in order to make this request. It will return a list that contains your webhooks with their id. Then you can unregister your webhook(s) and create new one(s). Is this clear ?

super-ienien commented 5 years ago

Sorry i didn't read all your message. You are already using the getWebhooks() method...

Ok so the doc for the unregister method is not complete... Sorry for that.

you need to use it like that :

userActivityWebhook.unregister({webhookId: webhooks.environments[0].webhooks[0].id});