【问题标题】:Why am I getting 404 ("Resource media not found") on the media upload from the docs?为什么我在从文档上传的媒体上收到 404(“找不到资源媒体”)?
【发布时间】:2019-06-27 03:57:14
【问题描述】:

将富媒体上传到 LinkedIn (https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/rich-media-shares#upload-rich-media) 的文档说要使用表单数据制作 POSThttps://api.linkedin.com/media/upload。据我所知,我在 Node 服务器上使用 request-promise 正确地做到了这一点,但我仍然得到 404。

最初我的文件有问题,但现在我认为我正在正确创建缓冲区。即使我不是,这也阻止了我提出请求,现在我是并且我认为这不会导致 404。

我也尝试过使用X-Restli-Protocol-Version1.0.02.0.0 版本(LinkedIn API 事物)。

// See LinkedIn docs on Rich Media shares https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/rich-media-shares

const stream = require('stream');
const rp = require('request-promise')

async function postRichMediaShare(accessToken) {
  try {
    const file = await rp({
      method: 'get',
      url: 'https://local-image-bucket.s3.amazonaws.com/Artboard+copy.png'
    });

    // Buffer magic
    const buffer = new Buffer.from(file);
    const bufferStream = new stream.PassThrough();
    bufferStream.end( buffer );
    bufferStream.pipe( process.stdout );

    const options = {
      method: 'post',
      url: 'https://api.linkedin.com/v2/media/upload',
      headers: { 'X-Restli-Protocol-Version': '2.0.0',
      "Authorization": `Bearer ${accessToken}` },
      formData: {
        file: {
          value: bufferStream,
          options: {
            filename: 'Artboard+copy.png',
            contentType: 'image/png'
          }
        }
      },
    };

    const response = await rp(options);
    console.log("response", response);

    return response;
  } catch (error) {
    throw new Error(error);
  }
}

我从 LinkedIn 收到此错误消息,而不是文档中建议的响应:

error: "{"serviceErrorCode":0,"message":"Resource media does not exist","status":404}"

【问题讨论】:

    标签: node.js linkedin linkedin-api


    【解决方案1】:

    我是个白痴。应该预期 404,因为我请求 https://api.linkedin.com/v2/media/upload 而文档说 https://api.linkedin.com/media/upload(没有 v2/)。我相信所有其他调用都是版本化的。也许有能力的LinkedIn员工阅读这篇文章可以为v2/开辟一条路线,做同样的事情。

    请注意,上面的代码可能还有其他问题,我仍在苦苦挣扎,但现在我正在处理这个问题范围之外的关于 404 的问题。

    【讨论】:

      猜你喜欢
      • 2019-05-06
      • 1970-01-01
      • 1970-01-01
      • 2018-01-12
      • 2016-07-16
      • 1970-01-01
      • 2013-09-09
      • 2012-10-05
      • 2016-12-05
      相关资源
      最近更新 更多