Retrieve full URL in Twitter Search API - twitter

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.

Related

Shorten URL in Swift iOS with your custom website domain name

I want to shorten a share URL I have in my app when users share a shop. I want a methodology or an API that allows me to shorten the URL to make it look clean but with my website's name.
for instance:
longURL: "https://example.com?x=somevalue&y=someothervalues"
Then when I shorten the URL with an API or method it would produce a small URL similar to this: "https://mywebsite.com/shortenedURLcode"
here is my code:
link = URL(string: "https://mywebsitename.com/share/?shop="+concatenate(getKey!,"&title="+shopName.text!.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!,"&desc="+summary.text!.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!,"&img="+profileImgURL))
I want to shorten the above link with my website's hostname.
How can I do that?
Here are two options to consider for shortening your URLs:
Bitly API
One option Bitly's API, which will allow you to make requests that return shortened links that fit the above mentioned criteria.
It appears to achieve the result you seek, you must make two requests: one to receive the link with custom domain, and a second to customize the "back half" (See revenant API Documentation in hyperlinked text).
The result of request #2 will contain your fully custom link.
Rebrandly API
The far better option in my opinion is Rebrandly. While I personally don't have any experience using any of Rebrandly's products, I would recommend this option as it has a generous free tier to get you started.
And best of all, the entire shortened link can be formulated in a single request. Will note that what Bitly calls a "back-half" is referred to as the "slashtag" by Rebrandly, but these terms both refer to the exact same thing.
API documentation can be found here.

Zapier to look up Twitter URL mentions

Is it possible to create a Zap that will look-up URL mentions on Twitter?
Been scratching my head with this one, since simply entering URL into Zapier's Twitter Search field doesn't seem to do the trick.
Is it at all possible? Twitter uses its URL shortening service t.co on all links posted. Might this be a reason for me not being able to find any mentions of my URL even when I post one myself? Twitter's native search function finds URL just fine, but not Zapier.
OK, I think I figured it out.
First, use Twitter's special "url" prefix for URL search:
url:amazon - will find URL with the word “amazon” anywhere within it.
Second, most importantly, it looks like the Twitter account I used for testing got ignored after a couple of same URL posts. So be aware of that too.

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.

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

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.

Anchor tags in urls & search engines, HOWTO?

How do I implement anchor tag urls so that search engines crawl my pages? Here's an example from twitter:
In search results it's:
http://twitter.com/username
When I click on it, it redirects me to
http://twitter.com/#!/username
How does twitter know when to redirect? Relying on a User-Agent doesn't seem such a good idea.
Twitter isn't optimizing their site for SEO. They have a special deal with Google so I wouldn't use them as an example. Google has support for hash URLs, which you can read about here https://developers.google.com/webmasters/ajax-crawling/docs/specification.
The main idea is that a URL like http://www.example.org/#!/my-url the crawlers convert to http://www.example.org/?_escaped_fragment_=/my-url. When Google encounters that URLs it makes a get requests to the alternative URL and will use that content to index it.

Resources