http-client and streaming endpoints pasted by pinkiesOut on Wed Mar 11 15:20:52 2015

(define twitter (make-oauth-service-provider
		  protocol-version: '1.0a
		  credential-request-url: "https://api.twitter.com/oauth/request_token"
		  owner-auth-url: "https://api.twitter.com/oauth/authorize"
		  token-request-url: "https://api.twitter.com/oauth/access_token"
		  signature-method: 'hmac-sha1))

;;; Set up the application to include your secret tokens (available at
;;; apps.twitter.com)
(define twitter-app
  (make-oauth-service
    service: twitter
    client-credential: (make-oauth-credential
			 "MySecret"
			 "MySecret")))

;;; Using the rest-bind egg, we can verify our
;;; credentals... 
;;; https://dev.twitter.com/rest/reference/get/account/verify_credentials 
(define-method (verify-credentials #!key include_entities skip_status)
  "https://api.twitter.com/1.1/account/verify_credentials.json"
  #f read-json #f)

;;; Set up some credentials
(define x (acquire-temporary-credential twitter-app))

;;; This is the VERIFIER URL for including in the call below
(uri->string (authorize-resource-owner twitter-app x))

;;; Visit the supplied URL in browser, allow app and retrive verifier
(define me (acquire-token-credential twitter-app x <VERIFIER>))


;;; This works for REST API
(with-oauth twitter-app me
	    (lambda ()
	      (call-with-input-request
	       "https://api.twitter.com/1.1/search/tweets.json?q=%23freebandnames&since_id=24012619984051000&max_id=250126199840518145&result_type=mixed&count=4"
	       #f
	       (cut read-string #f <>))))

;;; Now, with streaming API we get nothing...
(with-oauth twitter-app me
	    (lambda ()
	      (call-with-input-request
	       "https://stream.twitter.com/1.1/statuses/filter.json?delimited=length&track=espn"
	       #f
	       (cut read-string #f <>))))

Working code that never ends pasted by pinkiesOut on Wed Mar 11 19:05:41 2015

;;; This call should end things immediately, but does not
(with-oauth twitter-app me
	    (lambda ()
	      (call-with-input-request
	       "https://stream.twitter.com/1.1/statuses/filter.json?delimited=length&track=espn"
	       #f
	       (lambda (x)
		 (close-input-port (current-input-port))))))

;;; This should also end things, but does not
(with-oauth twitter-app me
	    (lambda ()
	      (call-with-input-request
	       "https://stream.twitter.com/1.1/statuses/filter.json?delimited=length&track=espn"
	       #f
	       (lambda (x)
		 (close-connection! "https://stream.twitter.com/1.1/statuses/filter.json?delimited=length&track=espn")))))

Code for collecting 8 tweets pasted by pinkiesOut on Wed Mar 11 19:52:35 2015

(with-output-to-file "./clucker-dump.json"
  (lambda ()
    (with-oauth twitter-app me
		(lambda ()
		  (call-with-input-request
		   "https://stream.twitter.com/1.1/statuses/filter.json?delimited=length&track=espn"
		   #f
		   (lambda (x)
		     (let lp ((line (read-line x))
			      (tweets 0))
		       (if (< tweets 9)
			   (unless (eof-object? line)
			     (print line)
			     (lp (read-line x) (+ tweets 1)))
			   (close-input-port x)))))))))

JSON cut off added by pinkiesOut on Wed Mar 11 19:53:24 2015

4709
{"created_at":"Wed Mar 11 18:47:24 +0000 2015","id":575729753531023360,"id_str":"575729753531023360","text":"RT @mt_hardison: ESPN filling up extra time between last game and UNC game with an extended Laettner interview. \nCruel trolling, ESPN","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":19640050,"id_str":"19640050","name":"Amanda Higgins","screen_name":"Higgie22","location":"Monessen, Pa","url":"http:\/\/www.instagram.com\/higgie22","description":"Stay Thirsty My Friends! *Burgh Verified*","protected":false,"verified":false,"followers_count":1193,"friends_count":1679,"listed_count":19,"favourites_count":7655,"statuses_count":47210,"created_at":"Wed Jan 28 06:57:44 +0000 2009","utc_offset":-14400,"time_zone":"Eastern Time (US & Canada)","geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/pbs.twimg.com\/profile_background_images\/403852808\/pittsburgh-shot.jpg","profile_background_image_url_https":"https:\/\/pbs.twimg.com\/profile_background_images\/403852808\/pittsburgh-shot.jpg","profile_background_tile":true,"profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/551185798679498752\/Zgl8pBJO_normal.jpeg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/551185798679498752\/Zgl8pBJO_normal.jpeg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/19640050\/1424668990","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"created_at":"Wed Mar 11 18:44:38 +0000 2015","id":575729057989554176,"id_str":"575729057989554176","text":"ESPN filling up extra time between last game and UNC game with an extended Laettner interview. \nCruel trolling, ESPN","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":995446226,"id_str":"995446226","name":"Michael Hardison","screen_name":"mt_hardison","location":"Somewhere on I-95","url":null,"description":"Graduate of UNC. Huge sports fan, movie buff & runner. Must love dogs, bar karaoke and peanut butter M&Ms. Sigma Phi. Tar Heel.\nContributor to @tarheeldepot","protected":false,"verified":false,"followers_count":529,"friends_count":373,"listed_count":5,"favourites_count":8230,"statuses_count":10921,"created_at":"Fri Dec 07 16:52:19 +0000 2012","utc_offset":-10800,"time_zone":"Atlantic Time (Canada)","geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"1A1B1F","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme9\/bg.gif","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme9\/bg.gif","profile_background_tile":false,"profile_link_color":"2FC2EF","profile_sidebar_border_color":"181A1E","profile_sidebar_fill_color":"252429","profile_text_color":"666666","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/563555743442296832\/jQoDGdPQ_normal.jpeg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/563555743442296832\/jQoDGdPQ_normal.jpeg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/995446226\/1421378155","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":7,"favorite_count":4,"entities":{"hashtags":[],"trends":[],"urls":[],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en"},"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"trends":[],"urls":[],"user_mentions":[{"screen_name":"mt_hardison","name":"Michael Hardison","id":995446226,"id_str":"995446226","indices":[3,15]}],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en","timestamp_ms":"1426099644440"}
4973
{"created_at":"Wed Mar 11 18:47:24 +0000 2015","id":575729754734784512,"id_str":"575729754734784512","text":"RT @IoveOfTheGame: This Deserves Endless RTs... http:\/\/t.co\/VAVDGC7ilR","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":3063893090,"id_str":"3063893090","name":"Dean Yoho","screen_name":"DeanYoho47","location":"","url":"http:\/\/www.hudl.com\/athlete\/4629984\/highlights\/177878376?autoplay=1","description":"| I can do all things through Christ who strengthens me -Philippians 4:13 |\nWHS | Varsity Football MLB | Varsity Track & Field |","protected":false,"verified":false,"followers_count":31,"friends_count":64,"listed_count":0,"favourites_count":3,"statuses_count":2,"created_at":"Fri Mar 06 02:47:31 +0000 2015","utc_offset":null,"time_zone":null,"geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/573676977141366784\/ZlShwF94_normal.jpeg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/573676977141366784\/ZlShwF94_normal.jpeg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/3063893090\/1425610277","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"created_at":"Wed Mar 04 22:12:49 +0000 2015","id":573244735021826048,"id_str":"573244735021826048","text":"This Deserves Endless RTs... http:\/\/t.co\/VAVDGC7ilR","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2266451123,"id_str":"2266451123","name":"\u24b6\u24e3\u24d7\u24db\u24d4\u24e3\u24d4 \u24c1\u24d8\u24d5\u24d4","screen_name":"IoveOfTheGame","location":"","url":null,"description":"-@Pberks08- \n\n\nDo it for the LoveOfTheGame","protected":false,"verified":false,"followers_count":35986,"friends_count":23252,"listed_count":34,"favourites_count":3,"statuses_count":581,"created_at":"Tue Jan 07 06:53:04 +0000 2014","utc_offset":-36000,"time_zone":"Hawaii","geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"3B94D9","profile_background_image_url":"http:\/\/pbs.twimg.com\/profile_background_images\/570045918628421632\/K34BuIVS.jpeg","profile_background_image_url_https":"https:\/\/pbs.twimg.com\/profile_background_images\/570045918628421632\/K34BuIVS.jpeg","profile_background_tile":true,"profile_link_color":"3B94D9","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/552867959438598145\/QbYJXO27_normal.jpeg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/552867959438598145\/QbYJXO27_normal.jpeg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2266451123\/1420649138","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":1035,"favorite_count":634,"entities":{"hashtags":[],"trends":[],"urls":[{"url":"http:\/\/t.co\/VAVDGC7ilR","expanded_url":"http:\/\/espn.go.com\/video\/clip?id=10889153","display_url":"espn.go.com\/video\/clip?id=\u2026","indices":[29,51]}],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en"},"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"trends":[],"urls":[{"url":"http:\/\/t.co\/VAVDGC7ilR","expanded_url":"http:\/\/espn.go.com\/video\/clip?id=10889153","display_url":"espn.go.com\/video\/clip?id=\u2026","indices":[48,70]}],"user_mentions":[{"screen_name":"IoveOfTheGame","name":"\u24b6\u24e3\u24d7\u24db\u24d4\u24e3\u24d4 \u24c1\u24d8\u24d5\u24d4","id":2266451123,"id_str":"2266451123","indices":[3,17]}],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en","timestamp_ms":"1426099644727"}
2363
{"created_at":"Wed Mar 11 18:47:28 +0000 2015","id":575729769951723521,"id_str":"575729769951723521","text":"While he was limited to six games last season, Ryan Mathews did have the fifth-highest yards after... - via @ESPN App http:\/\/t.co\/IxkOVssJZP","source":"\u003ca href=\"http:\/\/www.apple.com\" rel=\"nofollow\"\u003eiOS\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2377776761,"id_str":"2377776761","name":"Mamba\u2660\ufe0f","screen_name":"YungJefee_","location":"","url":null,"description":"Spencer\u2660\ufe0f\u2663\ufe0f","protected":false,"verified":false,"followers_count":335,"friends_count":258,"listed_count":1,"favourites_count":7289,"statuses_count":18923,"created_at":"Mon Mar 03 02:08:14 +0000 2014","utc_offset":null,"time_zone":null,"geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/573673932856954880\/gM2erUUO_normal.jpeg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/573673932856954880\/gM2erUUO_normal.jpeg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2377776761\/1425652894","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"trends":[],"urls":[{"url":"http:\/\/t.co\/IxkOVssJZP","expanded_url":"http:\/\/es.pn\/1KXzUYo","display_url":"es.pn\/1KXzUYo","indices":[118,140]}],"user_mentions":[{"screen_name":"espn","name":"ESPN","id":2557521,"id_str":"2557521","indices":[108,113]}],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en","timestamp_ms":"1426099648355"}
5319
{"created_at":"Wed Mar 11 18:47:32 +0000 2015","id":575729786951065600,"id_str":"575729786951065600","text":"RT @tommytomlinson: My latest story for @ESPN, on John Calipari, and what perfect means.  http:\/\/t.co\/G2X1XbMkd7","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":45665232,"id_str":"45665232","name":"William Downey","screen_name":"wkdowney","location":"Woodford County","url":null,"description":"#BBN #KentuckyProud","protected":false,"verified":false,"followers_count":253,"friends_count":401,"listed_count":1,"favourites_count":801,"statuses_count":940,"created_at":"Mon Jun 08 20:43:50 +0000 2009","utc_offset":-14400,"time_zone":"Eastern Time (US & Canada)","geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/pbs.twimg.com\/profile_background_images\/46414190\/UK.gif","profile_background_image_url_https":"https:\/\/pbs.twimg.com\/profile_background_images\/46414190\/UK.gif","profile_background_tile":false,"profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/479446727267975168\/WRGHW30Z_normal.jpeg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/479446727267975168\/WRGHW30Z_normal.jpeg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/45665232\/1384184231","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"created_at":"Wed Mar 11 17:15:45 +0000 2015","id":575706688755482625,"id_str":"575706688755482625","text":"My latest story for @ESPN, on John Calipari, and what perfect means.  http:\/\/t.co\/G2X1XbMkd7","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":28583238,"id_str":"28583238","name":"tommy tomlinson","screen_name":"tommytomlinson","location":"Charlotte, NC","url":"http:\/\/tommytomlinson.com","description":"Contributing writer, @ESPN. Authoring THE ELEPHANT IN THE ROOM (Simon & Schuster, 2016ish). Occasional side hustles. Husband of @alixfelsing.","protected":false,"verified":false,"followers_count":8141,"friends_count":948,"listed_count":313,"favourites_count":2260,"statuses_count":21016,"created_at":"Fri Apr 03 15:19:07 +0000 2009","utc_offset":-14400,"time_zone":"Eastern Time (US & Canada)","geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"A69AE6","profile_background_image_url":"http:\/\/pbs.twimg.com\/profile_background_images\/122586702\/billygraham_photo_quinn.JPG","profile_background_image_url_https":"https:\/\/pbs.twimg.com\/profile_background_images\/122586702\/billygraham_photo_quinn.JPG","profile_background_tile":true,"profile_link_color":"0084B4","profile_sidebar_border_color":"BDDCAD","profile_sidebar_fill_color":"DDFFCC","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/378136261\/SCAN0068_normal.JPG","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/378136261\/SCAN0068_normal.JPG","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/28583238\/1420654779","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":9,"favorite_count":19,"entities":{"hashtags":[],"trends":[],"urls":[{"url":"http:\/\/t.co\/G2X1XbMkd7","expanded_url":"http:\/\/espn.go.com\/espn\/feature\/story\/_\/id\/12454676\/university-kentucky-coach-john-calipari-changing-colle