Skip to content

node-red-node-twitter error by posting a tweet #665

Open

Description

@ever3001

Which node are you reporting an issue on?

Node-Red-Node-Twitter

What are the steps to reproduce?

  • Open an node red project
  • Install Node-Red-Node-Twitter
  • Insert a node twitter out
  • Configure credentials
  • Add a simple inject node with msg.payload = "Hello world" and msg.topic = ""
  • Connect inject node to twitter node
  • Deploy
  • Inject information to twitter node

What happens?

A message "TypeError: Cannot read property '0' of undefined" displays in debug tab

What do you expect to happen?

Tweet Hello world in the account configured

Please tell us about your environment:

  • Node-RED version: v1.1.2
  • node.js version: v12.18.2
  • npm version: 6.14.6
  • Platform/OS: MX-19.2_x64 patito feo May 31 2020
  • Browser: Version 83.0.4103.116 (Official Build) (64-bit)

Activity

  1. PlkMarudny commented on Jul 24, 2020

    @PlkMarudny

    I observed the same, but suddenly everything went back to normal. Guessing this was a Twitter glitch somehow.

  2. ever3001 commented on Jul 24, 2020

    @ever3001
    Author

    Oh you are right. Now it works somehow. Thank you! 👍

  3. johnmckerrell commented on Aug 6, 2020

    @johnmckerrell

    I am currently getting this, the stack reports:

    TypeError: Cannot read property '0' of undefined
        at /home/pi/.node-red/node_modules/node-red-node-twitter/27-twitter.js:645:66
        at runMicrotasks (<anonymous>)
        at processTicksAndRejections (internal/process/task_queues.js:97:5)
    

    That line of code is:

    node.error(result.body.errors[0].message,msg);
    

    I dumped the result body and it was showing:

    {
      request: '/1.1/statuses/update.json',
      error: 'Read-only application cannot POST.'
    }
    

    I just checked on Twitter's documentation though and they claim the error should be compatible with the existing code.

    Having the node's code so dependent on Twitter's API response structure could be considered a bad thing, but then knowing what the fallback should be is tricky. I've just tried the following which is quite "belt and braces" but might be considered overkill?

    if (result.body.errors && result.body.errors[0] && result.body.errors[0].message) {
      node.error(result.body.errors[0].message,msg);
    } else if (result.body.error) {
      node.error(result.body.error,msg);
    } else {
      node.error("Twitter gave status: "+result.status+", unexpected body: "+JSON.stringify(result.body),msg);
    }
    

    So in my circumstance the second if clause is triggering, but if that failed in the future it would fallback on just dumping out the entire body and reporting the status.

    Any thoughts?

  4. knolleary commented on Aug 6, 2020

    @knolleary
    Member

    @johnmckerrell adding better error handling would be welcome.

    The error you're hitting is because the credentials you are using don't have permission to post to the stream. I imagine that could be a common mistake made when setting up the credentials - so making sure the node reports back properly would be useful.

    If its something you wanted to PR, I happily take a look.

  5. johnmckerrell commented on Aug 6, 2020

    @johnmckerrell

    Thanks @knolleary yeah as soon as I actually had the error message I fixed the problem on my side. If the code I posted above seems reasonable I'll be happy to PR it sometime, first time committing so wasn't sure whether that code would make sense but I guess the ideal place to discuss it is on a PR!

  6. johnmckerrell commented on Aug 6, 2020

    @johnmckerrell

    (Worth reopening this issue until the fix is out? I don't appear to have privileges)

  7. ever3001 commented on Aug 6, 2020

    @ever3001
    Author

    The error is in Twitter App permissions. When you generate an app in Twitter, the default permissions are only Read (Read Tweets and profile information), so you need to change it for "Read and Write" or "Read + Write + Direct Messages".
    To change the permissions you need:

    1. Go to your dashboard (https://developer.twitter.com/en/portal/dashboard).
    2. Click on your app settings.
    3. Click on the button "edit" in section "App permissions".
    4. Change the permissions to "Read and Write" or "Read + Write + Direct Messages".

    After that you have to regenerate the Access Token & Secret Token to have the same permissions as the application:

    1. Go to your dashboard (https://developer.twitter.com/en/portal/dashboard).
    2. Click in Keys and tokens.
    3. Click in the button "Regenerate" in section "Authentication Tokens".

    After that you have to reconfigure the node in node-red with the new tokens and keys and now should work. That's how I find the solution to the problem. So for the error improvement, I will open the Issue again.

  8. ajlennon commented on Oct 21, 2021

    @ajlennon

    I love it when I'm trying to solve a problem and I find @johnmckerrell was there before me ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions