我使用下一段代码请求 2fa(双因素身份验证)的代码并且运行良好:
private async void TwilioSMS(object sender, EventArgs e)
{
RestSharp.RestClient client = new RestSharp.RestClient("https://api.authy.com/protected/json/phones/verification");
RestSharp.RestRequest request = new RestSharp.RestRequest("start", RestSharp.Method.POST);
numcheck = Numero.Text.Trim();
request.AddHeader("Content-Type", "application/json");
request.RequestFormat = RestSharp.DataFormat.Json;
string este = "{\"api_key\":\"" + apikey + "\",\"via\":\"sms\"," + "\"country_code\":52," + "\"phone_number\":"+numcheck + ",\"locale\":\"es\"}";
request.AddParameter("text/json", este, RestSharp.ParameterType.RequestBody);
RestSharp.IRestResponse response = await client.ExecuteTaskAsync(request);
respuesta = response.Content;
Console.WriteLine(respuesta);
}
但是当我尝试使用下一段代码进行验证时:
private async void VerifCode(object sender, EventArgs e)
{
try
{
if (numcheck == string.Empty) { numcheck = Numero.Text.Trim(); }
RestSharp.RestClient client = new RestSharp.RestClient("https://api.authy.com/protected/json/phones/verification");
RestSharp.RestRequest request = new RestSharp.RestRequest("check", RestSharp.Method.GET);
request.AddHeader("Content-Type", "application/json");
request.RequestFormat = RestSharp.DataFormat.Json;
string este = "{\"api_key\":\"" + apikey + "\",\"country_code\":52," + "\"phone_number\":" + numcheck + ",\"verification_code\":" + Confirmation.Text.Trim() + "}";
request.AddParameter("text/json", este, RestSharp.ParameterType.RequestBody);
RestSharp.IRestResponse response = await client.ExecuteTaskAsync(request);
respuesta = response.Content;
Console.WriteLine(numcheck);
Console.WriteLine(response.Content);
var listo = respuesta.Split(new string[] { "\"success\":" }, StringSplitOptions.RemoveEmptyEntries)[1];
if (listo.Contains("true"))
{
await DisplayAlert("Código correcto", "El código es correcto", "OK");
}
else
{
await DisplayAlert("Código incorrecto", "El código es incorrecto o no ha sido mandado", "OK");
}
}
catch { await DisplayAlert("Código incorrecto", "El código es incorrecto o no ha sido mandado", "OK"); }
}
我得到下一个错误:
{"error_code":"60001","message":"Invalid API key","errors":{"message":"Invalid API key"},"success":false}
我对两者都使用相同的 api 密钥,为什么会发生错误?