javascript – How do I goo.gl-shorten a url in js?

javascript – How do I goo.gl-shorten a url in js?

Its not super clear in the docs or error message, but your request should look like the following and all will be well:

var request = gapi.client.urlshortener.url.insert({
    resource: {longUrl: https://codepen.io/}
});

I think Ill drop the messy client library for this, when it turns out I can do it five lines of coffescript instead of loading all that cruft, as I already have jQuery around anyway: http://codepen.io/johan/pen/puJyH

api = https://www.googleapis.com/urlshortener/v1/url
api += ?key=#{key}  if key = location.search.slice 1

$.ajax
  url: api
  type: POST
  data: JSON.stringify(longUrl: url)
  contentType: application/json
  success: (got) ->
    alert shortened url: #{got.id}

javascript – How do I goo.gl-shorten a url in js?

Leave a Reply

Your email address will not be published.