I am trying to generate short link Using bitly but getting "Status = WaitingForActivation"
public async Task<string> GetShortUrl(string url)
{
var myAccessToken = "Token";
var client = new HttpClient();
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", $"Bearer {myAccessToken}");
var content = new
{
long_url = url
};
//HTTP POST
var resp = await client.PostAsJsonAsync("https://api-ssl.bitly.com/v4/shorten", content);
var link = await resp.Content.ReadAsStringAsync();
return link;
}
[HttpGet("redirectUser/{PlanId}")]
[ValidateModelState]
public async Task<IActionResult> sendNotification(Guid PlanId)
{
var surveylink = "https://chats.landbot.io";
// getting Status = WaitingForActivation
var shortLink = GetShortUrl(surveylink);
}
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
I am getting Status = WaitingForActivation at
var shortLink = GetShortUrl(surveylink);
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
CodePudding user response:
The simple reason for this issue is that when the below given love is being executed :-
var resp = await client.PostAsJsonAsync("https://api-ssl.bitly.com/v4/shorten", content);
It is causing the code to move to the next line without completing the current part. So, the next line :-
var link = await resp.Content.ReadAsStringAsync();
is unable to execute properly as a result.
What you can do to solve this issue is create a waiting period till some response is returned. Once a response is returned, then move to the next line and then return the link.