为什么从文档上传的媒体上出现404(“找不到资源媒体”)?

时间:2019-06-25 23:12:38

标签: node.js linkedin linkedin-api

将富媒体上传到LinkedIn(https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/rich-media-shares#upload-rich-media)的文档说,要使用表单数据将def "Expect that Application.otherMethod() is called"(){ given: def app = new Application() when: Application.main() then: 1 * Application.otherMethod() } 制作到POST。据我所知,我在Node服务器上使用https://api.linkedin.com/media/upload正确地做到了,但是我仍然得到404。

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

我还尝试使用request-promise(LinkedIn API事物)的1.0.02.0.0版本。

X-Restli-Protocol-Version

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

// 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);
  }
}

1 个答案:

答案 0 :(得分:0)

我是个白痴。应该会出现404,因为我正在请求https://api.linkedin.com/v2/media/upload,并且文档说https://api.linkedin.com/media/upload(否v2/)。我相信其他所有电话都已版本化。也许有能力的LinkedIn员工在阅读本文时,可能会为v2/做一条相同的事情。

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