我使用“https://api.linkedin.com/v2/assets?action=registerUpload”创建了图像共享上传网址并使用该上传网址我正在尝试将图片上传到链接但我从API收到错误请求400错误,请在下面找到代码片段,
private void UploadImageToLinkedIn(string accessToken)
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
client.DefaultRequestHeaders.Add("X-Restli-Protocol-Version", "2.0.0");
byte[] imgBytes = System.IO.File.ReadAllBytes("D:\\work\\All_Photos\\1_full.jpg");
using (MultipartFormDataContent fd = new MultipartFormDataContent())
{
var fileContent = new ByteArrayContent(imgBytes);
fileContent.Headers.Add("Content-Type", "multipart/form-data");
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "1_full" };
fd.Add(fileContent);
string postingURL = "https://api.linkedin.com/mediaUpload/C4E22AQFg1jP-2n4Jog/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQLl5BnZw1Rk0wAAAWk5k9KsK.........";
var result = client.PostAsync(postingURL, fd).Result;
}
}
}
我也曾在邮递员身上试过没有运气。谁能帮我吗?
注册上传后,您可以使用上传网址将图片上传到LinkedIn。 1.内容类型应该是application / binary 2.image path应该是绝对路径。例如:users / desktop / myimage.jpg我使用curl工作。