Invalid xml with RestSharp
本文关键字:RestSharp with xml Invalid | 更新日期: 2023-09-27 18:34:48
当我使用 RestSharp
通过 API 在LinkedIn中分享我的帖子时,它向我显示错误
Invalid xml {Expected elements 'post-network-update@...........'
public class LinkedInPost(string title, string description, string url, string imageUrl=null)
{
ApiBaseUrl111 = LLinkedInBaseUrllll;
var request = new RestRequest("v1/people/~/shares?format=json", Method.POST);
request.AddHeader("Authorization", "Bearer " + Token);
request.AddHeader("Content-Type", "application/json; charset=utf-8");
request.AddHeader("x-li-format", "json");
//request.RequestFormat = DataFormat.Json;
var model = new class
{
Comment = "This is my comment",
LinkedInContent = new LinkedInContent
{
LinkedInDescription = description,
LinkedInTitle = title,
Submittedurl = url,
Submittedimageurl = imageUrl
},
LinkedInVisibility = new LinkedInVisibility
{
LinkedInCode = "anyone"
}
};
request.AddJsonBody(model);
var response = Execute<class>(request);
return response;
}
当发布的 JSON 中缺少字段时,LinkedIn返回此错误。
在您的情况下,除非您在后台使用自定义序列化程序,否则 LinkedInContent
、 LinkedInVisibility
等可能不会序列化为 "content"
、"visibility"
等,这是LinkedIn正在寻找的 JSON 字段。
就我而言,我用三个M拼写了comment
。 :)
以下是将来搜索的完整错误:
{
"errorCode": 0,
"message": "Invalid xml {Expected elements 'post-network-update@http://api.linkedin.com/v1 id@http://api.linkedin.com/v1 visibility@http://api.linkedin.com/v1 ad-account@http://api.linkedin.com/v1 comment@http://api.linkedin.com/v1 attribution@http://api.linkedin.com/v1 content@http://api.linkedin.com/v1 mention@http://api.linkedin.com/v1 title@http://api.linkedin.com/v1 dsc-name@http://api.linkedin.com/v1 private-message@http://api.linkedin.com/v1 share-target-reach@http://api.linkedin.com/v1' instead of 'commment@http://api.linkedin.com/v1' here in element share@http://api.linkedin.com/v1}",
"requestId": "ODBIHNJYOZ",
"status": 400,
"timestamp": 1455664570337
}