Reputation: 11
I'm trying to implement auto post on Twitter using PHP.
But because of twitt's character limit I wanted to know how can I use tinyURL, instead of placing the full link, like http://www.appdropp.com/ios/stone-age-the-board-game/564247778
You see it's quite long...
I know services like:
But how can I use these services in bulk, to generate hundreds of links every day with PHP?
Upvotes: 0
Views: 1405
Reputation: 110
You can check Google API, but I'm not sure about that much bulk. I can suggest 3 solutions for you:
message + URL <= 140
)
and keep your automatic tweets length less than 140 characters. You can also try this (Check the PHP Source Code Example)
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
Upvotes: 0
Reputation: 1252
Note that
This method depends upon TinyURL page structure which may be changed in near future and don't use it in that much bulk Or ask them for API ?
You can use this way.
$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
..Second blockquote
contains shorten url $nodelist=$doc->getElementsByTagName('blockquote');
$blockquote=$nodelist->item(1) // grabbing shorten url blockquote 0:first 1:second
$shorten_url=$blockquote->$firstChild->NodeValue
Use any where you like.
For more info see tiny url page structure
Read more about DOMDocument
For goo.gl, read: https://developers.google.com/url-shortener
Upvotes: 1