When I share my post in linkedIn through Api using RestSharp
, it shows me the error
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;
}
LinkedIn returns this error when there are missing fields in the posted JSON.
In your case, unless you were using a custom serializer behind the scenes, LinkedInContent
, LinkedInVisibility
, etc. likely weren't being serialized to "content"
, "visibility"
, etc., which are the JSON fields that LinkedIn is looking for.
In my case, I had spelled comment
with three M's. :)
Here's the full error for future searches:
{
"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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.