我想在Twitter上使用PHP實現自動發佈。微小的URL使用PHP的自動twitts
但由於twitt的字符的限制,我想知道我怎麼可以使用TinyURL的,而不是把全部環節,像http://www.appdropp.com/ios/stone-age-the-board-game/564247778
你看,這是相當長的...
我知道般的服務:
- tinyurl.com
- goo.gl
但是我怎樣才能批量使用這些服務,每天用PHP生成數百個鏈接?
我想在Twitter上使用PHP實現自動發佈。微小的URL使用PHP的自動twitts
但由於twitt的字符的限制,我想知道我怎麼可以使用TinyURL的,而不是把全部環節,像http://www.appdropp.com/ios/stone-age-the-board-game/564247778
你看,這是相當長的...
我知道般的服務:
但是我怎樣才能批量使用這些服務,每天用PHP生成數百個鏈接?
您可以查看谷歌的API,但我不知道那麼多散裝。 我可以爲您推薦3種解決方案:
message + URL <= 140
) ,並將您的自動推文長度小於140個字符。你也可以嘗試this(檢查 PHP源代碼示例)
function CompressURL($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://"."to.ly/api.php?longurl=".urlencode($url)); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HEADER, 0); $shorturl = curl_exec ($ch); curl_close ($ch); return $shorturl; } echo CompressURL("http://twitter.com"); // Test
請注意, 此方法依賴於TinyURL頁面結構,它可能會在不久的將來被改變,並且不會在那麼多的批量中使用它或者要求它們使用API?
您可以使用這種方式。
$url='http://tinyurl.com/create.php?source=indexpage&url=<encoded url>
$doc=new DomDocuement();
$doc->loadHTMLFile($url); // this is page containing shorten url
shorten url
節點.. 二包含縮短的URL$nodelist=$doc->getElementsByTagName('blockquote');
$blockquote=$nodelist->item(1) // grabbing shorten url blockquote 0:first 1:second
$shorten_url=$blockquote->$firstChild->NodeValue
使用任何你喜歡的地方。
欲瞭解更多信息請參閱tiny url page structure
瞭解更多關於DOMDocument
爲goo.gl,閱讀:https://developers.google.com/url-shortener