GithubHelp home page GithubHelp logo

twitter-lib's People

Contributors

airhadoken avatar antgiant avatar bmomberger-bitovi avatar peterpcw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twitter-lib's Issues

geocode always returns blank - special character issue?

When using Geocode no results ever come back.

Example twitter search string: "#PoMo AND geocode:49.287907,-122.852812,100km"

Which gets translated as:

https://api.twitter.com/1.1/search/tweets.json?lang=en&count=5&since_id=0&include_entities=false&result_type=recent&q=%2523PoMo%20AND%20geocode%3A49.287907%252C-122.852812%252C100km

(even without the hashtag it doesn't work). Wondering if the commas are properly formatted (maybe they should be %2C instead of %252C?).

Is this still being maintained?

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

Alt-text for uploadMedia()

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

Quote tweet

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!

Find friends, favorites etc.

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?

Not sure what I am doing wrong, simple code to tweet from GAS

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

TransientProperties vs MemoryProperties

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.

tweet not getting posted through "service.sendTweet(status, params)" function despite successful authentication

My aim is to automate posting tweets at a particular date and time from google sheets.
For this, I have:

  1. created my developer account
  2. generated my access tokens and keys ("Created with Read and Write permissions")
  3. turned on essential API access in the Twitter API Developer site
  4. in authentication settings enabled OAuth1.0a (It shows"OAuth 1.0a turned on")
  5. also imported twitter-lib using the project key for the script in my google apps script project for the google sheet

Below is my sheet:
Google Sheet

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.

Evil-eval() service references & other hacks to prevent huge list of unused permission requirements.

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

Can uploadMedia() support chunked encoding for larger files?

@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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.