Long URLs from Twitter feeds without making additional API calls/HTTP requests - twitter

Is there any built-in way to get the long, expanded URL from a twitter RSS feed? Right now the feed lists all the urls as http://t.co.... I'd like to do what the Twitter display does and display the long URLs; I'd also like to avoid having to do either an API call or HTTP request for each URL in the feed. Ideally, I'd also like to avoid using the Twitter API directly but if that's the only way, so be it.
Clarification
I'm not interested in doing a separate request for every single t.co link, or calling the Twitter API. I was hoping there was a single request I could make that would include the long URLs in the metadata (or even provide the tweet in full expanded form as it appears on Twitter). Turns out the way to do this is by requesting the JSON version from search.twitter.com rather than the RSS feed, and tacking on include_entities=True.
Rewrite, hopefully this makes it more clear
I'm using http://search.twitter.com/search.rss to get a feed of tweets matching a search term. The feed contains only the shortened t.co urls. Is there a way to modify my request so that the tweets contain the expanded URLs instead?
The goal is to do just one request rather than having to go through the tweets and parse each t.co url separately (especially since for a feed with several dozen t.co urls, that means several dozen separate requests). If necessary, I am willing to use the Twitter API directly to do the search instead of using RSS, but for my purposes using a feed is more ideal.

No, Twitter does not offer a urls entity in its RSS responses, nor does the include_entities option appear to work. You'll have to use a different response format e.g. JSON (with which you can use the include_entities option which includes an entities['urls'][n]['expanded_url'] object), or "unshorten" the URLs yourself after the fact.

There is a way to do this without using the Twitter API directly. You can use one of several resources,
http://expandurl.appspot.com/
API call prototype : http://expandurl.appspot.com/expand?url=
http://longurl.org
API call prototype : http://api.longurl.org/v2/expand?url=
http://unshort.me/
API call prototype: http://api.unshort.me/?r=http://
of course you can also use the Twitter API directly for this as Jordan mentioned by including &include_entities=1 or true as a parameter to some calls.
also try to CURL the URL and see what information you can gleam from that. I think this pretty much exhausts the options.

Related

Get tweet count of shares for multiple URLs with one request

I know how to get the tweet count of shares for one URL with the following request:
https://cdn.api.twitter.com/1/urls/count.json?url=[URL]
What I don't know is how to get the tweet count of shares for multiple URLs with just one request, maybe something like this:
cdn.api.twitter.com/1/urls/count.json?url=[URL1,URL2,URL3,...]
Facebook already has this functionality:
graph.facebook.com/?ids=[URL1,URL2,URL3,...]
I was wondering if Twitter has this as well.
I don't think is is supported.
Also this URL is not supposed to be available for the public and you shouldn't use it, especially since Twitter plans to shut it down in the near future (this month, I think).
You should look into the the Twitter REST and Streaming APIs instead.
https://dev.twitter.com/streaming/overview
https://dev.twitter.com/rest/public
Twitter says one of these should be used, these are officially supported.
But so far, I haven't found a way to easily query the number of tweets for a URL using these APIs though.

Displaying tweets from multiple users (similar to Embedded Timelines) without twitter-side user lists

I am new to Twitter and need some tips.
I need to display tweet feed from multiple users on some webpage.
The first thing I stumbled upon is Embedded Timelines. It allows to display tweets from list of users but the gotcha is that those lists should be maintained on Twitter-side (i.e. I cannot specify #qwe and #asd only on my side and get timeline without adding those users into list on Twitter-side).
The thing is that list of users that should be included into timeline is dynamic and managing those lists through Twitter API will probably be painful. Not to mention that my website will probably generate tons of those lists and I feel that I will violate some api quotas sooner or later.
So, my question is - am I stuck with using Embedded Timelines that refer some user list on Twitter-side and managing those lists through, say Twitter REST api, or there is a simplier way to do what I want?
It's pretty simple to display tweets for multiple users.
Links to start with
This post explains some of the search queries you can make
This post is a simple library to make requests to the twitter API that 'just works'
Your Query
Okay, so you want multiple users. The endpoint you're looking at using is the search/tweets one: https://api.twitter.com/1.1/search/tweets.json.
The query string uses :from and you can interpolate multiple froms with AND/OR.
An example query for the GET request:
?q=from:user1+OR+from:user2
Read more about the search API queries here.
Your "over-the-quote" issue
This is something you're going to need to figure out yourself - depending on the number of requests you expect to make, and the twitter imposed limits, maybe some sort of caching or saving information when you hit your limit, and only pull back from the cache whilst you're hitting your limit..

Searching Twitter feeds

I'm looking to take information from Twitter feeds such as removed posts. Is it possible to do this through some sort of string match search by looking for keywords, that is, "this post removed"?
This is for an Arduino project.
It should be. Twitter just turned off their old API, though, so as long as you're willing to get an API key, you should be fine (https://dev.twitter.com). Grab the data with loadBytes or loadStrings called on the API URL and then start walking through the data you got back (http://processing.org/reference/loadStrings_.htm) -- which in the new API will be JSON. You can use a JSON library to turn that into an actual object, but frankly if you want to do text matching, which you do, then there's really no need for Object repacking.

How to add Twitter Expanded Tweets? (was: twitter media preview card for my site?)

I googled a lot about how to make twitter media preview for my website entities if they are linked in a tweet like images below:
Any idea where can I find some documentation about it? Or a tutorial? Is this possible or these media/site previews are hardcoded in twitter?
EDIT:
so, what I need:
If someone links my site on twitter, my widget appear under the tweet, like below:
UPDATE 2012-06-13
It appears this is an Expanded Tweet - -what the requirements are to integrate these expansions into Twitter are do not appear to be displayed - but this sure is interesting.
Nope your in luck. They're not hardcoded into Twitter, they're available in the JSON response. You actually have in your post the word you need to google for entities.
You can add include_entities=1 to the end of most REST api calls and it will give you expanded information about the URL's contained within the JSON. It will split out all the URL's where you can parse out the Youtube links for example. The JSON also includes a special media_url entity but it only works for pictures. In any case, you can still parse out the media easily like youtube with a regex match because you get the URL's split out nicely with this include_entities=1 parameter.
example call :
http://api.twitter.com/1/statuses/user_timeline.json?screen_name=twitterapi&include_entities=1
more documentation : https://dev.twitter.com/docs/tweet-entities
answer edited below based on clarification:
Editing Twitter itself with previews is impossible and it's also ineffective. 75% of traffic to Twitter happens outside of Twitter.com. However the most probable solution to achieving this request would be to download a browser extension.
This extension for example enbales previews of webpages directly in the users stream content preview pane on Twitter.com
https://chrome.google.com/webstore/detail/oijgblonhcagdhfbgjilnpjipmijimmn

Retrieve full URL in Twitter Search API

I am using the Twitter Search API to search for a URL. Here's an example:
http://search.twitter.com/search.json?q=url.com
The JSON response gives me the shortened URL of each search result. Is there a way for me to retrieve the full URL of each result?
From 11/2011, you can use the include_entities=true parameter to retrieve full tweet entities, which include the expanded URL (and a lot more)
https://dev.twitter.com/docs/using-search
You will have to pragmatically request each URL yourself and see where it redirect to.
On Twitter Search, you can use the same URL endpoint that Twitter Search uses to expand shortened URLs: http://search.twitter.com/hugeurl. For example, if you wanted to expand the shortened URL http://bit.ly/jIhqhq:
$ curl "http://search.twitter.com/hugeurl?url=http://bit.ly/jIhqhq"
http://edition.cnn.com/2011/SPORT/football/05/03/may.03.cnn.top.10/index.html/
This will only work for the more popular shorteners (bit.ly, j.mp, etc.) Also, this AJAX endpoint is pretty aggressively rate-limited, so don't expect to be able to use this for a production application, but something like 10 times an hour should be fine.
Not currently through Twitter. On Twitter.com, those shortened URLs are automatically expanded into something readable, however search.twitter.com doesn't seem to be expanding the t.co shortened URLs at this time.

Resources