airhadoken / twitter-lib Goto Github PK
View Code? Open in Web Editor NEWEasy Twitter API integration for Google Apps Script
Easy Twitter API integration for Google Apps Script
Currently slashes sent to fetchTweets()
become %252F
when sent to the API. This fails searches for e.g. particular lists; not double escape, and should be sent as %2F
.
By default Twitter search returns items in reverse chronological order when searching. When iterating with a tweet processor, the oldest Tweet is processed first (indices length - 1 down to 0), but push() is used to put the results into the result array. Either process tweets in order returned, or change push() to unshift().
When using Geocode no results ever come back.
Example twitter search string: "#PoMo AND geocode:49.287907,-122.852812,100km"
Which gets translated as:
(even without the hashtag it doesn't work). Wondering if the commas are properly formatted (maybe they should be %2C instead of %252C?).
When I tried to add the id MKvHYYdYA4G5JJHj7hxIcoh8V4oX7X1M_ to my library it says: "Check the ID and access permissions and try again."
Can you please advise? Thanks
Twitter has released a new API endpoint for adding accessibility hints to media uploads.
What Twitter hasn't done is allowed it to be sent in the initial upload.
Since Google Script fetch calls are synchronous, this is just a matter of adding in the setting of metadata as a second step after the media has been uploaded, if it is specified, before returning the media ID to the user.
More info here: https://blog.twitter.com/2016/alt-text-support-for-twitter-cards-and-the-rest-api
Hi,
Are you going to make this update to the Google library?
Hi, can you help me in figuring out how do I quote a tweet? I know the sendtweet function accepts tweet text, params and options.
OAuth.prototype.sendTweet = function(tweet, params, options)
But I don't know how should I pass the quoted tweet URL or tweet ID to make my tweet quote another tweet.
I tried passing the tweet URL (in the form of https://twitter.com/statuses/<tweet_id>) to the function I am calling (by adding 'attachment_url=' at the front and passing as both params and options separately), but it keeps on giving me an error.
Thanks!
The ScriptApp.getProjectKey method is deprecated.
Any alternative ?
Hi, I've got this working perfectly for searching tweets and retweeting. But I'm looking for a way to find friends of a particular id or find tweets favorited by a user. Is there any way I can do it?
First uncovered in http://stackoverflow.com/questions/35944948/what-parameters-will-twitter-libs-fetchtweets-method-accept
Please run a comprehensive test (as much as possible) on fetchTweets with all special characters and all tags, to make sure they're returning the same tweets that a Twitter web search would return.
Have been using this lib for some time. Now getting this exception when using the method fetchTweets
.
Looks like there is a limit on the length of URL. How to fix this?
The TransientProperties class and fetchTweets() are currently unusable, as they both rely on Underscore.js and v24 removed that dependency.
So not sure what I am doing wrong, but getting generic error when trying to use the following code in Google App Scripts. I have added the TwitterLib library in google app scripts version 25. (for some reason I can only add in classic view, so go back there to add, then back to new interface to use).
function sendTweet(status) {
status = "Is this a cool tweet?";
var twitterKeys = {
TWITTER_CONSUMER_KEY: '**************************',
TWITTER_CONSUMER_SECRET: '**************************',
TWITTER_ACCESS_TOKEN: '**************************-**************************',
TWITTER_ACCESS_SECRET: '**************************',
};
var props = PropertiesService.getScriptProperties();
props.setProperties(twitterKeys);
var service = new Twitterlib.OAuth(props);
if (service.hasAccess()) {
var response = service.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
}
}
}
My consumer key/secret -> API Key and Secret below and my access token/secret -> Access Token and Secret below. I am seeing the following error which doesn't give me a lot to go on as far as errors and been fighting to figure this out for days.
Send tweet failure. Error was:
{"name":"Exception"}
options were:
{"method":"POST","payload":"status=Is%20this%20a%20cool%20tweet%3F","headers":{"Authorization":"OAuth oauth_consumer_key=\"**************************\", oauth_nonce=\"**************************\", oauth_signature=\"**************************%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1644456180\", oauth_token=\"**************************-**************************\", oauth_version=\"1.0\""},"escaping":false}
I am finding no help anywhere to figure this out, and it feels pretty simple, so not sure what I am missing or where to reach out. If you have any good examples or resources to read on, would love it! I have looked everywhere. Thank you!
phi
User @dkodr suggested support for reading and managing DMs.
There are only three endpoints associated with DMs (get, post, and destroy), so this should be a fairly easy addition. GET method is documented here: https://dev.twitter.com/rest/reference/get/direct_messages
Since TransientProperties was added to Twitter lib (because Google puts limits on the number of property accesses per day), MemoryProperties has been added to OAuth1. TransientProperties is a little bit nicer (e.g. you can pass an object to the constructor) but the two are almost functionally equivalent.
Please port MemoryProperties from OAuth1, make any desired upgrades, and preserve both names for the time being. It may be prudent to deprecate the TransientProperties name.
My aim is to automate posting tweets at a particular date and time from google sheets.
For this, I have:
I want to process my text in the sheet which I do in the function prepareMyTweet1()
and then send it through the function sendMyTweet1()
. I have edited bits and pieces of the original code from this source.
Below is my code:
function myFunction1() {
prepareMyTweet1();
sendMyTweet1();
}
function prepareMyTweet1() {
// process my tweet text from google sheet
}
const twitterKeys = {
TWITTER_CONSUMER_KEY: "my_key",
TWITTER_CONSUMER_SECRET: "my_secret",
TWITTER_ACCESS_TOKEN: "my_access_token",
TWITTER_ACCESS_SECRET: "my_access_secret",
}
function sendMyTweet1() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var startRowNumber = 2;
var endRowNumber = sheet.getLastRow();
var props = PropertiesService.getScriptProperties();
props.setProperties(twitterKeys);
var params = new Array(0);
var service = new Twitterlib.OAuth(props);
var myTweet;
var identifier;
for (var currentRowNumber = startRowNumber; currentRowNumber <= endRowNumber; currentRowNumber++) {
var row = sheet.getRange(currentRowNumber + ":" + currentRowNumber).getValues();
console.log("This the tweet text: ",row[0][2])
// check that the second column (Date) is equal to today
if (isToday1(row[0][0])) {
myTweet = row[0][2];
identifier = currentRowNumber - 1;
if (!service.hasAccess()) {
console.log("Authentication Failed");
}
else {
console.log("Authentication Successful");
var status = myTweet + "\n\n" + "#Automated #GoogleSheets";
try {
var response = service.sendTweet(status, params);
console.log("Response by Twitter: ",response);
}
catch (e)
{
console.log("Error",e);
}
}
break;
}
}
}
function isToday1(date) {
var today = new Date();
var dateFromRow = new Date(date);
return dateFromRow.getDate() == today.getDate() &&
dateFromRow.getMonth() == today.getMonth() &&
dateFromRow.getFullYear() == today.getFullYear()
}
The execution log is as below:
9:01:25 AM Notice Execution started
9:01:25 AM Info This the tweet text: This is a test tweet
9:01:25 AM Info Authentication Successful
9:01:25 AM Info Send tweet failure. Error was:
{"name":"Exception"}
options were:
{"method":"POST","payload":"status=This%20is%20a%20test%20tweet%0A%0A%23Automated%20%23GoogleSheets","headers":{"Authorization":"OAuth oauth_consumer_key=\"my_key\", oauth_nonce=\"my_auth\", oauth_signature=\"my_signature\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1655177485\", oauth_token=\"my_token\", oauth_version=\"1.0\""},"escaping":false}
9:01:25 AM Info Response by Twitter: null
9:01:26 AM Notice Execution completed
I tried finding a solution on stackoverflow, but there is so little coverage on the topic that I am unable to find anything useful. The closest I got was with this question. But again, this too isn't of much help in my case.
Is Tweet deletion on the roadmap?
Google has deprecated the ScriptApp.getProjectKey()
function but says that getScriptId()
will work in all cases where getProjectKey()
was needed.
https://developers.google.com/apps-script/reference/script/script-app#getScriptId()
As of April 29, 2023 Twitter appears to be fully shutting down all V 1 APIs and switching to v2 APIs only. Since this is a V 1 API library, I think that someone else may need to take up the mantle of creating a V2 version of this repo.
I'd be happy to be proved wrong, but I believe this may be the end for this library.
Currently Twitter Lib requires authorization to use Document Service, Spreadsheet service, Mail service, etc. even when it's not needed. These can be accessed on-demand instead by doing e.g. eval('Spreadsheet' + 'App').getUi();
instead of SpreadsheetApp.getUi();
Plus, since the only place where the container
property is used is determining how to access the user's UI when doing two-step* authorization, don't bother going through the try-catch flow on object creation. Wait until it's needed.
*two-step auth is used when the user hasn't pre-set an access token; the flow to set an access token is presented to the user of a document or spreadsheet, or mailed to the user if nonesuch exists
@kfinley already tried to do this but gave up. Maybe tinker with it if you're bored.
Synchronous execution is a definite problem here. If media can't be uploaded in a timely manner the script will probably time out.
Building the perfect POST body is probably the biggest challenge. Recall that trying to manually create the multipart/form-data block was frustrating (read: miserable failure) until you let the script engine do it automatically. This is something completely not supported by fetch(), so it may be impossible, who knows.
Doesn't seem like the API currently has support for following a user: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/post-friendships-create
And maybe this as well to check whether you're friends first without trying to follow: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friendships-show
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.