32 : Could not authenticate you

oauth

#1

I am trying to register a webhook for direct messages using the API https://api.twitter.com/1.1/account_activity/webhooks.json

Keep getting the error.
“code”: 32, “message”: “Could not authenticate you.”

  1. Tried using POSTMAN filling the authorization tab with OAuth 1.0 tab
  2. Tried register through standard twitter lib for nodejs “twitter-node-client”
  3. Tried register through node.js
    All the options are throwing this error.

I have also tried to

  • Regenerate consumer key/secret & access token/secret (number of times)

App have following permission
"Read, write, and direct messages"

Except this api call, almost all other api call works fine
e.g. Following api calls works fine
https://api.twitter.com/1.1/account/verify_credentials.json

My app is approved. Got mail from twitter that “Your Twitter developer account application has been approved!”

Please someone help; I read almost all the posts related to this for the last few days.

code used using “twitter-node-client”

var error = function (err, response, body) {
	console.log('ERROR: %j', err);
};
var success = function (data) {
	console.log('Data [%s]', data);
};

var Twitter = require('twitter-node-client').Twitter;

var twitter = new Twitter({
	"consumerKey": "xxxx",
	"consumerSecret": "xxx",
	"accessToken": "xxxx-xxxxx",
	"accessTokenSecret": "xxxxx"
});

//Example calls
// This works
// twitter.getUserTimeline({ screen_name: 'xxxxx', count: '10'}, error, success);

twitter.postCustomApiCall('/account_activity/webhooks.json',{url: 'https://xxxxxxxx.execute-api.ap-south-1.amazonaws.com/dev'}, error, success);

code using node.js

var request = require('request')

var WEBHOOK_URL = 'https://xxxxxx.execute-api.ap-south-1.amazonaws.com/dev'

var twitter_oauth = {
  consumer_key: "xxxxxx",
  consumer_secret: "xxxxx",
  token: "xxx-xxxx",
  token_secret: "xxxxx"
}

// request options
var request_options = {
  url: 'https://api.twitter.com/1.1/account_activity/webhooks.json',
  oauth: twitter_oauth,
  headers: {
    'Content-type': 'application/x-www-form-urlencoded'
  },
  form: {
    url: WEBHOOK_URL
  }
}

console.log('request_options: %j', request_options);

// POST request to create webhook config
request.post(request_options, function (error, response, body) {
  console.log(body)
})

#2

Hey @eso - It is likely you only have access to the All Activities beta - please be sure to check those docs.


#3

Thank you!

I used ‘All activities’ api instead of ‘Direct Messages’ and it worked fine.

i.e. used
https://api.twitter.com/1.1/account_activity/all/:env_name/webhooks.json
instead of
https://api.twitter.com/1.1/account_activity/webhooks.json