views:

47

answers:

1

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");

  xmlhttp.open("POST", "http://goo.gl/api/url?
     [email protected]&url=" + urlEscaped
     + "&auth_token=" + auth_token, false);
  xmlhttp.onload = xmlhttpLoad;
  xmlhttp.send(null);
}

FYI again

check http://marcusnunes.com/api-goo.gl.php

A: 

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.

Matthew Flaschen
Open a new window is ok,but the problem is user and auth_token, I want user can trace there shorten url.
guilin 桂林