查找 t.co 链接指向的位置 [英] Find where a t.co link goes to
问题描述
给定一个 t.co 链接,我如何才能找到链接解析的位置?例如,如果我有 t.co/foo,我想要一个返回 domain.com/bar 的函数或进程.
Given a t.co link, how can I find see where the link resolves? For example, if I have t.co/foo, I want a function or process that returns domain.com/bar.
推荐答案
我会远离您无法控制的外部 API.这只会在您的应用程序中引入一个潜在的故障点,并且可能会花费您的费用.
I would stay away from external APIs over which you have no control. That will simply introduce a dependency into your application that is a potential point of failure, and could cost you money to use.
CURL 可以很好地做到这一点.这是我在 PHP 中的做法:
CURL can do this quite nicely. Here's how I did it in PHP:
function unshorten_url($url) {
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_FOLLOWLOCATION => TRUE, // the magic sauce
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYHOST => FALSE, // suppress certain SSL errors
CURLOPT_SSL_VERIFYPEER => FALSE,
));
curl_exec($ch);
return curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
}
我确信这可以适用于其他语言,甚至可以在 UNIXy 系统上使用 curl
命令编写脚本.
I'm sure this could be adapted to other languages or even scripted with the curl
command on UNIXy systems.
http://jonathonhill.net/2012-05-18/unshorten-urls-with-php-and-curl/
这篇关于查找 t.co 链接指向的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!