The longest part of this process will be going to http://code.google.com/apis/console/ and signing up for your api key. Once you have that secured, you can use that in the code below. The only other change needed is to add your user id. I use the user id as a simple authentication for the shortener as an added measure. You will use the same id in the url entered in the TweetDeck options and the code below.
Once you've made your adjustments, save the code as googl.php in your root folder, you can begin using a similar url to the on below to return your short url. You can really place it and name it where ever and whatever you would like, just make the necessary adjustments.
http://www.your_domain_here.com/googl.php?user=user_name&lu=%@
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); $lu = htmlspecialchars_decode($_REQUEST['lu']); $gak = 'INSERT_KEY_HERE'; $gep = 'https://www.googleapis.com/urlshortener/v1'; $gaurl = $gep.'/url?key='.$gak; function shortUrl($url,$longUrl){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $requestData = array('longUrl' => $longUrl); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json')); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestData)); $result = curl_exec($ch); curl_close($ch); return $result; } //You can remove the if statement to remove the id check in the url if($_REQUEST['user']==='INSERT_USER_ID') { $rwurl = json_decode(shortUrl($gaurl,$lu)); echo htmlspecialchars($rwurl->id); } ?>
Comments
There are no comments