Bad Authentication data - code 215


#1

Hello,

Getting error: { errors: [ { code: 215, message: ‘Bad Authentication data.’ } ] }

Code:

config.oauth.nonce = Math.random().toString(36).replace(/[^a-z]/, ‘’).substr(2);
config.oauth.timestamp = Math.round(new Date().getTime()/1000);
config.oauth.signature = oauthSignature.generate(“POST”, “https://api.twitter.com/1.1/direct_messages/events/new.json”, {
oauth_consumer_key: config.oauth.consumer_key,
oauth_token: config.oauth.access_token,
oauth_signature_method: config.oauth.signature_method,
oauth_timestamp: config.oauth.timestamp,
oauth_nonce: config.oauth.nonce,
oauth_version: config.oauth.oauth_version
}, config.oauth.consumer_secret, config.oauth.token_secret);
options.headers.Authorization = ‘OAuth oauth_consumer_key="’+config.oauth.consumer_key+’",oauth_token="’+config.oauth.access_token+’",oauth_signature_method=“HMAC-SHA1”,oauth_timestamp="’+config.oauth.timestamp+’",oauth_nonce="’+config.oauth.nonce+’",oauth_version=“1.0”,oauth_signature="’+config.oauth.signature+’"’;
console.log("\noptions:", options, “\n”);
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});

let quick_reply_body = { event:
{ type: ‘message_create’,
message_create:
{ target: { recipient_id: recipientId },
message_data:
{ text: ‘What’s your favorite type of bird?’,
quick_reply:
{ type: ‘options’,
options:
[ { label: ‘Red Bird’,
description: ‘A description about the red bird.’,
metadata: ‘external_id_1’ },
{ label: ‘Blue Bird’,
description: ‘A description about the blue bird.’,
metadata: ‘external_id_2’ },
{ label: ‘Black Bird’,
description: ‘A description about the black bird.’,
metadata: ‘external_id_3’ },
{ label: ‘White Bird’,
description: ‘A description about the white bird.’,
metadata: ‘external_id_4’ } ] } } } } };

let options = { method: ‘POST’,
url: ‘https://api.twitter.com/1.1/direct_messages/events/new.json’,
headers:
{
Authorization: ‘’,
‘Content-Type’: ‘application/json’ },
body: quick_reply_body,
json: true };

Let me know what I am doing wrong and if you need any more detail.


#2

Looks like you might be missing the consumer secret and token secret (if I’ve read your code correctly).


#3

Hi @StreeboTwitBot, it sounds like @jenvander may be correct.

Error code 215 is triggered when there is bad authentication data. It corresponds with HTTP 400. The method requires authentication but it was not presented or was wholly invalid.

Please check the authentication details you’re passing through are correct.

Hamza


#4