[英]Using WordPress REST API in C# to get post author display name
[英]rest api wordpress creating a post with specific categories using c#
我正在嘗試使用模塊 / package wordpressPCL 向我的帖子添加類別,但我似乎無法解決是否有人知道如何創建具有特定類別集的帖子。
錯誤是它不接受 integer 但 ID 是 integer 我的代碼。
private async Task mysite()
{
int[] genres = { 5 };
var client = new WordPressClient("https://mysite/wp-json/");
client.Auth.UseBasicAuth("user", "password");
var post = new Post()
{
Title = new Title(textBox1.Text),
Content = new Content(textBox2.Text),
Categories = new Categories(genres)
};
await client.Posts.CreateAsync(post);
}
錯誤在第 10 行
第一次使用圖書館任何幫助將不勝感激
您必須首先獲取類別的 int,然后您可以將其放置在作為端點的一部分調用的 URL 中。
http://example.com/wp-json/wp/v2/posts?categories=3160
因此,您使用包含的類別編號完成 URL。 為了幫助您了解事情是如何工作的,我建議您像我一樣使用程序 postman,並嘗試先在您的網站上發布一個帖子。
{
"title": "test post from postman",
"content": "<p>This is a paragraph</p>",
"status": "draft"
}
通過正確的授權,您可以從 postman 內部將此作為原始 json 進行發布,這證明您的系統設置正確,然后您可以在程序中實現發布和 json 編碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.