asp.net 403错误提示403错误API

k97glaaz  于 2023-02-26  发布在  .NET
关注(0)|答案(1)|浏览(139)

我试图实现whatsapp业务API,但我得到禁止的错误,我想这是因为我没有足够的权限。我也实现了这段代码的 Postman 它的工作很好,但它不工作的应用程序,我不知道为什么?

var client = new HttpClient();
        var request = new HttpRequestMessage(HttpMethod.Post, "https://graph.facebook.com/v15.0/110474688636083/messages");
        request.Headers.Add("Authorization", "Bearer TOKEN");
        var content = new StringContent("{\n    \"messaging_product\": \"whatsapp\",\n    \"to\": \"WHATSAPPNO\",\n    \"type\": \"template\",\n    \"template\": {\n        \"name\": \"hello_world\",\n        \"language\": {\n            \"code\": \"en_US\"\n        }\n    }\n}", null, "application/json");
        request.Content = content;
        var response = await client.SendAsync(request);
        response.EnsureSuccessStatusCode();
        Console.WriteLine(await response.Content.ReadAsStringAsync());

谢谢你抽出时间

odopli94

odopli941#

您没有指定访问令牌。

request.Headers.Add("Authorization", "Bearer TOKEN");

此处的TOKEN是占位符,而不是真实的的标记

相关问题