在网站中集成Google的URL缩短程序[重复]

问题描述 投票:0回答:1

是否有可能将URL shortener service整合到一个网站?说我有一个“share”按钮,生成一个长URL,我需要它来缩短它?

我试过以下代码:

      $.ajax({
          url: 'https://www.googleapis.com/urlshortener/v1/url?key={APIkey}',
          type: 'POST',
          contentType: 'application/json; charset=utf-8',
          data: '{ longUrl: "' + longURL +'"}',
          success: function(response) {
              $('#inputBox').val(response.id);
              console.log(response);
          }
      });

但我在控制台中收到错误400代码。

javascript html url
1个回答
0
投票

请使用谷歌,你会发现更多的结果。如果您无法获得支持或帮助代码,请发布任何内容。 Google拥有完整开发文档的网站。请访问此处:developers.google.com/url-shortener/v1/getting_started

  curl https://www.googleapis.com/urlshortener/v1/url \
  -H 'Content-Type: application/json' \
  -d '{"longUrl": "http://www.google.com/"}'
© www.soinside.com 2019 - 2024. All rights reserved.