简体   繁体   English

如何延长使用Bitly(JavaScript)缩短的URL?

[英]How to Lengthen URLs shortened with Bitly (JavaScript)?

I've figured out how to shorten URLs with the Bitly API (code below). 我已经弄清楚了如何使用Bitly API(下面的代码)缩短URL。 But I don't know how to lengthen them again. 但是我不知道如何再次延长它们。 The callback in the function below returns an object that has the longurl and the shorturl stored as properties. 下面函数中的回调返回一个对象,该对象具有存储为属性的longurl和shorturl。 But I need a function that I can enter a shortURL and retrieve a longURL for my web application. 但是我需要一个函数,可以为我的Web应用程序输入shortURL并检索longURL。 Someone else has asked this on here, but for C, not for JavaScript. 有人在这里问过这个问题,但是对于C语言,不是对JavaScript语言。 LongURL.org has some documentation for how to implement this with their API, but the docs are for PHP and Ruby. LongURL.org有一些文档,说明如何使用其API来实现此功能,但是该文档适用于PHP和Ruby。 Tried to adapt it for JavaScript but got errors. 试图使其适应JavaScript,但出现错误。

This seems like something that's probably trivial. 这似乎是微不足道的。 Is there a straightforward way to achieve what I want here? 有没有一种简单的方法可以在这里实现我想要的?

function getShortURL(url, callback)
{
   var accessToken =  [my access token]
   var url = 'https://api-ssl.bitly.com/v3/shorten?access_token=' + accessToken + '&longUrl=' + encodeURIComponent(url);

$.getJSON(
    url,
    {},
    function(response)
    {
        if(callback)
            callback(response.data.url);
            console.log(response) 
    }
);
}

var shortURL;

getShortURL("http://stackoverflow.com/questions/33783996/how-to-make-a-url-shortener-with-the-bitly-api-with-javascrpt-jquery?noredirect=1#comment55334692_33783996", function(url){ shortURL = url; console.log(url) })

Please look at the Bit.ly documentation 请查看Bit.ly文档

http://dev.bitly.com/links.html#v3_expand http://dev.bitly.com/links.html#v3_expand

Its explained how to get the original url... 它解释了如何获取原始网址...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM