I want to add a button at my webpage, when I click the button it will try to locate goo.gl and input the current url.
How could I use goo.gl service by javascript?
FYI:
I found somthing at here http://www.labnol.org/internet/create-google-short-url/11748/ but how to import this function? var auth_token = getUrlShorteningRequestParams(url);
function shortify(url)
{
var auth_token = getUrlShorteningRequestParams(url);
var urlEscaped = escape(url).replace(/\+/g,"%2B");
开发者_如何学JAVA xmlhttp.open("POST", "http://goo.gl/api/url?
user=toolbar@google.com&url=" + urlEscaped
+ "&auth_token=" + auth_token, false);
xmlhttp.onload = xmlhttpLoad;
xmlhttp.send(null);
}
FYI again
check http://marcusnunes.com/api-goo.gl.php
goo.gl's API requires a POST
request to http://goo.gl/api/shorten?url=URL
, which means you can't do it in pure content (in a regular web page) JavaScript.
I developed a service that supports this using JSONP. However, it's become a victim of its own success, and now frequently exceeds the App Engine quota.
EDIT: The JavaScript code you've posted is from a Chrome extension. It can be done in privileged browser extensions; I wrote a similar Firefox extension.
The PHP API also seems fine. However, there is a new API (/shorten
) that doesn't require the token. Also, it doesn't seem to have a JSONP version for use with JavaScript.
You can create short URLs on client side using bit.ly service:
jQuery on the fly URL shortener
精彩评论