Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't send new direct messages #42

Open
smithjessk opened this issue Apr 24, 2016 · 2 comments
Open

Can't send new direct messages #42

smithjessk opened this issue Apr 24, 2016 · 2 comments

Comments

@smithjessk
Copy link

smithjessk commented Apr 24, 2016

I believe that this is an OAuth implementation problem because this task works correctly when done with twitter.

I know that the tokens, etc. are correct because I used them to properly view my direct messages.

Error:

URL [https://api.twitter.com/1.1/direct_messages/new.json?screen_name=jessdawess&text=This%20is%20a%20test]
ERROR: [object Object]
RESPONSE: [object Object]
BODY: {"errors":[{"code":32,"message":"Could not authenticate you."}]}

Source:

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

var config = {
    "consumerKey": process.argv[2],
    "consumerSecret": process.argv[3],
    "accessToken": process.argv[4],
    "accessTokenSecret": process.argv[5],
    "callBackUrl": process.argv[6]
};

var twitterClient = new Twitter(config);

twitterClient.postCustomApiCall('/direct_messages/new.json', {
    screen_name: process.argv[7],
    "text": "This is a test"
}, error, success);

function error(error, response, body) {
    console.log("ERROR: " + error);
    console.log("RESPONSE: " + response);
    console.log("BODY: " + body);
}

function success(response) {
    console.log("RESPONSE: " + response);
}
@kevin-smets
Copy link

kevin-smets commented Sep 26, 2017

It's due to a problem in the postCustomApiCall, see #37

Here's my working code:

const path = require('path');
const config = require('../data/twitter_config.json');

const TWITTER_BASE_URL = 'https://api.twitter.com/1.1';
const Twitter = require('twitter-node-client').Twitter;

const twitter = new Twitter(config);

//Callback functions
const error = function (err, response, body) {
    console.log('ERROR [%s]', JSON.stringify(err, null, 2));
};

const success = function (data) {
    console.log('Data [%s]', data);
};

twitter.doPost(`${TWITTER_BASE_URL}/direct_messages/new.json`, {
    user_id: '123456',
    text: 'This is easy.'
}, error, success);

@dcromster
Copy link

Still not work with code from @kevin-smets :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants