Search code examples
node.jstwittertwitter-oauth

How to register a webhook url in Twitter?


How to register a Twitter Webhook URL in Twitter? I am successful in authorizing my app using application-only authentication. I believe that app-only authentication is required in sending POST Request in https://api.twitter.com/1.1/account_activity/webhooks.json.

So Here is my code,

HTTP.call('POST', 'https://api.twitter.com/oauth2/token', {
    params: { 'grant_type':'client_credentials'},
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
        'Authorization': 'Basic '+base64token
    }
},function (error, response) {
    if (!error && response.statusCode == 200) {
        token = response.data.access_token;

        HTTP.call('POST', 'https://api.twitter.com/1.1/account_activity/webhooks.json', {
            params: { 'url':'https://someurl.com/twitter'},
            headers: {
                'Authorization': 'Bearer '+token
            }
        },function (error, response) {
            if (!error && response.statusCode == 200) {
                console.log(response);
            } else {
                console.error(error.message);
            }
        }); 
    } else {
        console.error(error.message);
    }
});

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

What is the problem here? How can I solve this issue?


Solution

  • That error is caused by supposedly breaching terms of service. It's reasonably common and easy enough to get resolved.

    Determining whether your app has been restricted

    • Log into the account that you used to register the application
    • Visit Twitter's application management site (https://apps.twitter.com)
    • On that page,"Unable to perform write actions" will appear below the name of your application only if the app can no longer perform write actions;

    enter image description here

    Result of Restrictions

    Attempts to access write-based Twitter API methods, such as statuses/update or favorites/create, through an API key in this state will result in our API returning an HTTP 403 response error: “Application cannot perform write actions. Contact Twitter Platform Operations through https://support.twitter.com/forms/platform.”

    How to resolve

    Raise a ticket on the Twitter support page, here: https://support.twitter.com/forms/platform

    Appealing only takes 5 minutes, and Twitter is very fast to resolve