Php 为什么Linkedin Ugc Image Post返回500错误?

Php 为什么Linkedin Ugc Image Post返回500错误?,php,curl,linkedin,linkedin-api,php-curl,Php,Curl,Linkedin,Linkedin Api,Php Curl,我正在使用LinkedIn v2 api进行图像共享。有三个步骤,根据 注册要上载的图像 将您的图像上载到LinkedIn 创建图像共享 我使用php curl通过了前两个,但第三个被卡住了。 步骤3,使用ugcPost完成 以下是我发送给ugc端点的帖子正文: { "author": "urn:li:person:{id-redacted}", "lifecycleState": "PUBLISHED", "specificContent": { "co

我正在使用LinkedIn v2 api进行图像共享。有三个步骤,根据

  • 注册要上载的图像
  • 将您的图像上载到LinkedIn
  • 创建图像共享
  • 我使用php curl通过了前两个,但第三个被卡住了。 步骤3,使用ugcPost完成

    以下是我发送给ugc端点的帖子正文:

    {
        "author": "urn:li:person:{id-redacted}",
        "lifecycleState": "PUBLISHED",
        "specificContent": {
            "com.linkedin.ugc.ShareContent": {
                "shareCommentary": {
                    "text": "hello"
                },
                "shareMediaCategory": "IMAGE",
                "media": {
                    "stats": "READY",
                    "description": {
                        "text": "this is a descriptoin"
                    },
                    "media": "urn:li:digitalmediaAsset:{id-redacted}",
                    "title": {
                        "text": "this is some title text"
                    }
                }
            }
        },
        "visibility": {
            "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
        }
    }
    
    下面是我用来用php发送curl post请求的代码:

        curl_setopt($ch, CURLOPT_URL, $ugcPostEndpoint);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        curl_setopt($ch, CURLOPT_STDERR, $out);
    
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json","X-Restli-Protocol-Version: 2.0.0"));
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
        $response = curl_exec($ch);
        $response_status = strval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
    
    从curl返回此值:

     Hostname was found in DNS cache
       Trying 108.174.10.12...
     Connected to api.linkedin.com (108.174.10.12) port 443 (#2)
     successfully set certificate verify locations:
       CAfile: none
      CApath: /etc/ssl/certs
     SSL connection using {redacted}
     Server certificate:
            subject: C=US; ST=California; L=Mountain View; O=LinkedIn Corporation; CN=tablet.linkedin.com
            start date: 2018-03-30 00:00:00 GMT
            expire date: 2020-04-27 12:00:00 GMT
            subjectAltName: api.linkedin.com matched
            issuer: C=US; O=DigiCert Inc; CN=DigiCert SHA2 Secure Server CA
            SSL certificate verify ok.
     POST /v2/ugcPosts?oauth2_access_token={redacted} HTTP/1.1
    Host: api.linkedin.com
    Accept: */*
    Content-Type:application/json
    X-Restli-Protocol-Version: 2.0.0
    Content-Length: 734
    
     upload completely sent off: 734 out of 734 bytes
    < HTTP/1.1 500 Server Error
    < X-LI-ResponseOrigin: RGW
    < Content-Type: application/json
    < X-RestLi-Error-Response: true
    < X-Restli-Gateway-Error: false
    < X-RestLi-Protocol-Version: 2.0.0
    < X-Li-Fabric: prod-ltx1
    < Transfer-Encoding: chunked
    < Connection: keep-alive
    < X-Li-Pop: prod-edc2
    < X-LI-Proto: http/1.1
    < X-LI-UUID: {redacted}
    < Set-Cookie: {redacted}
    < X-LI-Route-Key: {redacted}
    <
     Connection #2 to host api.linkedin.com left intact
    
    在DNS缓存中找到主机名 正在尝试108.174.10.12。。。 已连接到api.linkedin.com(108.174.10.12)端口443(#2) 已成功设置证书验证位置: 卡菲尔:没有 CApath:/etc/ssl/certs 使用{redact}的SSL连接 服务器证书: 主题:C=美国;ST=加利福尼亚州;L=山景;O=LinkedIn公司;CN=tablet.linkedin.com 开始日期:2018-03-30 00:00:00 GMT 过期日期:2020-04-27 12:00:00 GMT subjectAltName:api.linkedin.com匹配 发行人:C=美国;O=DigiCert公司;CN=DigiCert SHA2安全服务器CA SSL证书验证正常。 POST/v2/ugcPosts?oauth2_access_token={redact}HTTP/1.1 主持人:api.linkedin.com 接受:*/* 内容类型:application/json X-Restli-Protocol-Version:2.0.0 内容长度:734 上传已完全发送:734字节中的734字节
    为什么会发生这个错误?据我所知,我正在遵循所有示例/文档。(我知道500个错误最终可能是一个问题,但根据我的经验,在处理API500错误时,通常意味着curl请求在某种程度上是错误的。

    如果其他人有类似的问题,我就知道我做错了什么

    正文的媒体部分必须是数组中的第0个元素,如下所示:

     "media": [
                {
                    "status": "READY",
                    "description": {
                        "text": "this is a description"
                    },
                    "media": "urn:li:digitalmediaAsset:{id}",
                    "title": {
                        "text": "this is some title text"
                    }
                }
            ]
    
    不是这个:

         "media":
                {
                    "status": "READY",
                    "description": {
                        "text": "this is a description"
                    },
                    "media": "urn:li:digitalmediaAsset:{id}",
                    "title": {
                        "text": "this is some title text"
                    }
                }
    

    LinkedIn文档并没有让这一点变得非常明显。

    您是否将OAuth 2.0访问令牌添加到
    授权
    头中?