使用相同的长网址在v3和v4 api调用之间略有缩短的网址

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

[我们想将集成从v 3迁移到v4,在测试过程中,我们注意到,比较v3和v4返回的lin,返回的缩短的url是不同的,即使我们将相同的long url作为参数值发送也是如此。

由于我们的合同中的URL数有一个最大限制,因此即使在v3中已经发送并注册了v4中的长url缩短的url,也将被算作新的url吗?

此外,v3中缩短的网址(在迁移之前)在2020年1月1日之后(v3不再可用时)仍然可以使用吗?

rest api migration migrate bit.ly
1个回答
0
投票
****** Migrating from v3 to v4 of the Bitly API - Bitly V4 code for ASP.NET Applications *******


public string Shorten(string groupId, string token, string longUrl)
{
//string post = "{\"group_guid\": \"" + groupId + "\", \"long_url\": \"" + longUrl + "\"}";
string post = "{ \"long_url\": \"" + longUrl + "\"}";// If you've a free account.
string shortUrl = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api-ssl.bitly.com/v4/shorten");


try
{
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

request.ServicePoint.Expect100Continue = false;
request.Method = "POST";
request.ContentLength = post.Length;
request.ContentType = "application/json";
request.Headers.Add("Cache-Control", "no-cache");
request.Host = "api-ssl.bitly.com";
request.Headers.Add("Authorization", "Bearer " + token);

using (Stream requestStream = request.GetRequestStream())
{
byte[] postBuffer = Encoding.ASCII.GetBytes(post);
requestStream.Write(postBuffer, 0, postBuffer.Length);
}

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader responseReader = new StreamReader(responseStream))
{
string json = responseReader.ReadToEnd();
shortUrl = Regex.Match(json, @"""link"": ?""(?[^,;]+)""").Groups["link"].Value;

//return Regex.Match(json, @"{""short_url"":""([^""]*)""[,}]").Groups[1].Value;
}
}
}
}
catch (Exception ex)
{
LogManager.WriteLog(ex.Message);
}

if (shortUrl.Length > 0) // this check is if your bit.ly rate exceeded
return shortUrl;
else
return longUrl;
}
© www.soinside.com 2019 - 2024. All rights reserved.