bit.ly

What is the best way in PHP or JS to expand shortened URLs like Bitly, Tinyurl to find the original URL?

大兔子大兔子 提交于 2019-11-30 19:09:24
问题 I am using the Twitter and Facewbook API to pull posts that potentially contain shortened URLs using bit.ly or TinyURL like services. I need to do a real-time expansion to get the original URL then pull content from that URL into my app. 回答1: You can use CURL to expand a short URL. Try this: function traceUrl($url, $hops = 0) { if ($hops == MAX_URL_HOPS) { throw new Exception('TOO_MANY_HOPS'); } $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1);

Determine Final Destination of a Shortened URL in PHP?

被刻印的时光 ゝ 提交于 2019-11-30 15:24:04
How can I do this in PHP? e.g. bit.ly/f00b4r ==> http://www.google.com/search?q=cute+kittens In Java, the solution is this: You should issue a HEAD request to the url using a HttpWebRequest instance. In the returned HttpWebResponse, check the ResponseUri. Just make sure the AllowAutoRedirect is set to true on the HttpWebRequest instance (it is true by default). (Thx, casperOne) And the code is private static string GetRealUrl(string url) { WebRequest request = WebRequest.Create(url); request.Method = WebRequestMethods.Http.Head; WebResponse response = request.GetResponse(); return response

Using Only Javascript To Shrink URLs Using The Bit.ly API

血红的双手。 提交于 2019-11-30 10:48:58
问题 I'm playing a bit with Javascript these days... I was shrinking some URLs using bit.ly to tweet them, then I started to think on a automated process that could use their API to shrink the URLs I wanted, then I looked up on their documentation, and I saw that they only support PHP(with some Javascript), but there is anyway that I could make this using only Javascript? 回答1: Here is an example how to get a shortened URL with Bitly API and jQuery, no server side code required. function get_short

How to get long URL from short URL?

元气小坏坏 提交于 2019-11-30 00:56:15
Using Ruby, how do I convert the short URLs (tinyURL, bitly etc) to the corresponding long URLs? I don't use Ruby but the general idea is to send an HTTP HEAD request to the server which in turn will return a 301 response (Moved Permanently) with the Location header which contains the URI. HEAD /5b2su2 HTTP/1.1 Host: tinyurl.com Accept: */* RESPONSE: HTTP/1.1 301 Moved Permanently Location: http://stackoverflow.com Content-type: text/html Date: Sat, 23 May 2009 18:58:24 GMT Server: TinyURL/1.6 This is much faster than opening the actual URL and you don't really want to fetch the redirected URL

Using Only Javascript To Shrink URLs Using The Bit.ly API

蓝咒 提交于 2019-11-29 23:13:45
I'm playing a bit with Javascript these days... I was shrinking some URLs using bit.ly to tweet them, then I started to think on a automated process that could use their API to shrink the URLs I wanted, then I looked up on their documentation, and I saw that they only support PHP(with some Javascript), but there is anyway that I could make this using only Javascript? Here is an example how to get a shortened URL with Bitly API and jQuery, no server side code required. function get_short_url(long_url, login, api_key, func) { $.getJSON( "http://api.bitly.com/v3/shorten?callback=?", { "format":

Determine Final Destination of a Shortened URL in PHP?

只愿长相守 提交于 2019-11-29 22:13:23
问题 How can I do this in PHP? e.g. bit.ly/f00b4r ==> http://www.google.com/search?q=cute+kittens In Java, the solution is this: You should issue a HEAD request to the url using a HttpWebRequest instance. In the returned HttpWebResponse, check the ResponseUri. Just make sure the AllowAutoRedirect is set to true on the HttpWebRequest instance (it is true by default). (Thx, casperOne) And the code is private static string GetRealUrl(string url) { WebRequest request = WebRequest.Create(url); request

How to get long URL from short URL?

岁酱吖の 提交于 2019-11-28 21:41:33
问题 Using Ruby, how do I convert the short URLs (tinyURL, bitly etc) to the corresponding long URLs? 回答1: I don't use Ruby but the general idea is to send an HTTP HEAD request to the server which in turn will return a 301 response (Moved Permanently) with the Location header which contains the URI. HEAD /5b2su2 HTTP/1.1 Host: tinyurl.com Accept: */* RESPONSE: HTTP/1.1 301 Moved Permanently Location: http://stackoverflow.com Content-type: text/html Date: Sat, 23 May 2009 18:58:24 GMT Server:

How to get redirecting url link with php from bit.ly

房东的猫 提交于 2019-11-28 08:21:32
问题 I'm trying to get url links to those bit.ly redirects. I've tried to open bit.ly links with file_get_contents but it already gets content from redirected site, but how to get its url? 回答1: I was unaware of the bit.ly API, here is the raw way to do it: $context = array ( 'http' => array ( 'method' => 'GET', 'max_redirects' => 1, ), ); @file_get_contents('http://bit.ly/cmUTtb', null, stream_context_create($context)); echo 'Redirect to: ' . str_replace('Location: ', '', $http_response_header[6])

jQuery on the fly URL shortener

家住魔仙堡 提交于 2019-11-27 11:57:43
I'm looking for an on the fly URL shortener much like how tweetdeck works. I have found many jQuery and general javascript plugins that take a url and run it through a shortening service such as bit.ly when a button is pressed. However, I have not been able to find one that does it on the fly. My first question is does this already exist someplace? Secondly, if it doesn't, then what would be the best way to recognize a URL that needs to be shortened inside a textbox? My thoughts: On onKeyUp of that text area run through the text looking for http If found grab the whole URL (how do I determine

How do short URLs services work?

跟風遠走 提交于 2019-11-27 10:01:53
How do services like TinyURL or Metamark work? Do they simply associate the tiny URL key with a [virtual?] web page which merely provide an "HTTP redirect" to the original URL? or is there more "magic" to it ? [original wording] I often use URL shortening services like TinyURL, Metamark, and others, but every time I do, I wonder how these services work. Do they create a new file that will redirect to another page or do they use subdomains? Abel No, they don't use files. When you click on a link like that, an HTTP request is send to their server with the full URL, like http://bit.ly/duSk8wK