You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LinkedIn API图片上传持续返回PROCESSING_FAILED问题求助

解决LinkedIn API图片上传PROCESSING_FAILED问题

核心问题定位

你的代码在**步骤2(图片上传)**的请求格式不符合LinkedIn要求,导致图片上传后无法被正常处理,最终返回PROCESSING_FAILED。

具体修复方案

1. 修正PUT上传的请求体格式

LinkedIn要求图片上传的PUT请求直接将图片二进制数据作为请求体,而AddFile方法会生成multipart/form-data格式请求,不符合要求。修改步骤2代码:

using (var uploadClient = new RestClient())
{
    var uploadRequest = new RestRequest(uploadUrl, Method.Put);
    // 初始化上传返回的upload URL已包含临时鉴权信息,无需再携带Authorization头
    uploadRequest.AddHeader("Content-Type", "image/png"); // 确保和实际图片类型匹配
    
    var imgUploadStream = await image.GetStreamAsync();
    // 重置流位置到开头,避免读取空内容
    imgUploadStream.Position = 0;
    // 直接将流作为请求体发送
    uploadRequest.AddParameter("image/png", imgUploadStream, ParameterType.RequestBody);
    
    var uploadResponse = await uploadClient.ExecuteAsync(uploadRequest);
    if (!uploadResponse.IsSuccessful) 
        throw new Exception($"上传失败:{uploadResponse.StatusCode} - {uploadResponse.Content}");
}

2. 验证上传URL的正确性

确保从步骤1获取的uploadUrl完整且未被修改,LinkedIn返回的URL包含临时鉴权参数,不能截断或修改。

3. 优化轮询策略

  • 增加初始等待时间,避免LinkedIn未开始处理就查询状态
  • 提升最大尝试次数(5次可能不足)
  • 改用await Task.Delay()替代Thread.Sleep,避免阻塞线程:
var imageOk = false;
var attempts = 0;
const int maxAttempts = 12; // 最多轮询60秒
do
{
    await Task.Delay(5000);
    attempts++;
    
    var pollRequest = new RestRequest($"images/{imgResponseData!.value.image}", Method.Get);
    pollRequest.AddHeader("Authorization", $"Bearer {token}");
    pollRequest.AddHeader("LinkedIn-Version","202309");
    
    var pollResponse = await client!.ExecuteAsync(pollRequest);
    if (!pollResponse.IsSuccessful)
        throw new Exception($"查询状态失败:{pollResponse.StatusCode}");
    
    var pollData = JsonConvert.DeserializeObject<LinkedInPollResponse>(pollResponse.Content!);
    if (pollData?.status == "AVAILABLE")
    {
        imageOk = true;
        break;
    }
    if (pollData?.status == "PROCESSING_FAILED")
        throw new Exception($"图片处理失败,ID:{pollData.id}");
        
} while (attempts < maxAttempts);

if (!imageOk)
    throw new Exception("图片状态查询超时");

4. 额外检查点

  • 确认图片无损坏:换用其他PNG/JPG图片测试,排除文件本身问题
  • 验证owner参数:确保步骤1传入的author是正确的组织URN(urn:li:organization:xxxxxx),与token的w_organization_social权限匹配
  • 检查LinkedIn版本:当前使用的202309版本兼容,无需调整

内容的提问来源于stack exchange,提问作者instantiator

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 18:13:33