In Google Apps Script I have this piece of code in my project to send a tweet ( also in jsBin ):
function sendTweet(status) { var twitterKeys= { TWITTER_CONSUMER_KEY: "x", TWITTER_CONSUMER_SECRET: "x", TWITTER_ACCESS_TOKEN: "x", TWITTER_ACCESS_SECRET: "x" }; var props = PropertiesService.getScriptProperties(); props.setProperties(twitterKeys); twit = new Twitter.OAuth(props); var service = new Twitter.OAuth(props); if ( service.hasAccess() ) { var response = twit.sendTweet(status); if (response) { Logger.log("Tweet ID " + response.id_str); } else { // Tweet could not be sent // Go to View -> Logs to see the error message } } } sendTweet("test");
But the problem is that I get this error:
TypeError: Cannot read property "text" from undefined. (line 293, file "twitter", project "Twitter lib")
Line 293 from version 21 of the Twitter lib library ( MKvHYYdYA4G5JJHj7hxIcoh8V4oX7X1M_ ).
The "test" message actually gets twitter, despite this error. Does anyone know how to fix this?
To repeat the error, you noticed an error:
TypeError: "" undefined. ( 293, "", "Twitter lib" )
sendTweet() , . .
sendTweet()
/** * Upload a tweet to Twitter with optional media. * * @param {string | Tweet} tweet the status text to send as a Twitter update * @param {optional object} params any additional parameters to send as part of the update post * @return {object} the Twitter response as an object if successful, null otherwise */ OAuth.prototype.sendTweet = function(tweet, params) { var i; var payload = { //<=== 293 "status" : (tweet.text || tweet) };
status, "test".
status
tweet :
tweet
text
, , tweet.text, , , tweet. tweet.text (.. ), TypeError .
tweet.text
, . , tweet text .
Tweet. Tweet Twitter API v1.1 , , , text, status . , status - text.
function sendTweet(status) { if (typeof status === string) status = {text:status}; ...
. , 294 :
"status" : (tweet.hasOwnProperty("text") ? tweet.text : tweet)
:
"status" : (typeof tweet === 'object' ? tweet.text : tweet)
, . .
, Twitter Lib . @Mogsdad Twitter. , , script, Google Script.
, , script. , "" sendTweet, , Script , "" .
sendTweet
sendTweet , status undefined. undefined twit.sendTweet(), , .
undefined
twit.sendTweet()
, , - , "", :
function sendTestTweet() { sendTweet("test"); }
Source: https://habr.com/ru/post/1623372/More articles:How to install bazel and tensorflow on Red Hat 6.7 - compilationJPA / Spring / Delete object, type Mismatch (int / long for id) - javaGet a list of tuple lists by combining tuple elements? - pythonUse sudo: true with one element of the build matrix in travis.ci? - travis-cihow do I get listview to respond to touch - listviewWhat parameters will the Twitter lib fetchTweets () method use - javascriptThe total amount due to the interval - rSwift Generic with Type First Known at Runtime - genericsWhy does std :: cin change the value of its operand, even if it does not work? - c ++State construction for reusable components and browser history - javascriptAll Articles