From 1c1b53425f1d3140bb712989d4e929c16536c2e0 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 8 Jun 2018 12:55:19 +0100 Subject: [PATCH] Fix tweet with image --- social/twitter/27-twitter.html | 19 +++++++++++++++++-- social/twitter/27-twitter.js | 15 +++++++++++++++ social/twitter/package.json | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/social/twitter/27-twitter.html b/social/twitter/27-twitter.html index a3646468..b501f407 100644 --- a/social/twitter/27-twitter.html +++ b/social/twitter/27-twitter.html @@ -59,12 +59,27 @@ }, label: function() { if (this.screen_name) { - return "@"+this.screen_name + return (this.screen_name[0]!=="@"?"@":"")+this.screen_name } else { return "Twitter: "+this.id } }, - exportable: false + exportable: false, + oneditsave: function() { + var trimFields = [ + "consumer_key", + "consumer_secret", + "access_token", + "access_token_secret" + ]; + // Just in case any whitespace has crept in with the copy-paste of the fields + trimFields.forEach(function(field) { + var v = $("#node-config-input-"+field).val(); + v = v.trim(); + $("#node-config-input-"+field).val(v); + + }); + } }); })(); diff --git a/social/twitter/27-twitter.js b/social/twitter/27-twitter.js index de89376e..531011af 100644 --- a/social/twitter/27-twitter.js +++ b/social/twitter/27-twitter.js @@ -10,6 +10,9 @@ module.exports = function(RED) { function TwitterCredentialsNode(n) { RED.nodes.createNode(this,n); this.screen_name = n.screen_name; + if (this.screen_name && this.screen_name[0] !== "@") { + this.screen_name = "@"+this.screen_name; + } } RED.nodes.registerType("twitter-credentials",TwitterCredentialsNode,{ credentials: { @@ -396,6 +399,18 @@ module.exports = function(RED) { access_token_key: credentials.access_token, access_token_secret: credentials.access_token_secret }); + + var oa = new OAuth( + "https://api.twitter.com/oauth/request_token", + "https://api.twitter.com/oauth/access_token", + credentials.consumer_key, + credentials.consumer_secret, + "1.0", + null, + "HMAC-SHA1" + ); + + node.on("input", function(msg) { if (msg.hasOwnProperty("payload")) { node.status({fill:"blue",shape:"dot",text:"twitter.status.tweeting"}); diff --git a/social/twitter/package.json b/social/twitter/package.json index a179e78e..2499af52 100644 --- a/social/twitter/package.json +++ b/social/twitter/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-twitter", - "version": "1.0.0", + "version": "1.0.1", "description": "A Node-RED node to talk to Twitter", "dependencies": { "twitter-ng": "0.6.2",