Linkedin Marketing API 3 月 31 日查询更新

Linkedin Marketing API March 31 queries update

有些人可能知道,Linkedin Marketing API 宣布他们将从 2021 年 3 月 31 日开始拒绝 API 不符合新标准的电话。所以我开始更新我的服务。然而,存在这样的问题。文档中给出的示例 CURL 命令不起作用。 Related announcement

你以前遇到过这样的问题吗?如果我需要给你看几个例子:

curl -X POST https://api.linkedin.com/v2/adCreativesV2 \
  -H 'X-HTTP-Method-Override: PUT' \
  -H 'Content-Type: multipart/mixed; boundary=xyz;' \
  -H 'X-RestLi-Method: BATCH_PARTIAL_UPDATE' \
  -H 'Authorization: Bearer access_token' \
  -H 'X-RestLi-Protocol-Version: 2.0.0' \
  --data $'--xyz\r\nContent-Type: application/json\r\n\r\n{"entities": {{"47770196": {"patch": {"$set": {"status": "ACTIVE"}}}}}}\r\n--xyz--'

回复:

{
    "serviceErrorCode": 0,
    "message": "Invalid tunneled request - Missing start boundary",
    "status": 400
}

文档中提到的 GET 请求转换为 POST 的示例工作正常,但是 post 请求中使用的 header: -H Content-Type: multipart / mixed; boundary = xyz; 导致问题。

编辑:

正如 Matteo 在下面所说,问题出在 \r\n 但是,我在我的应用程序中使用了 PHP CURL。我不确定如何将 \r\n 翻译成马车 return。这是一个用法示例:

    $ch = curl_init();

    $jsonData = "
    --xyz
    Content-Type: application/json" 
    . json_encode($parameters, JSON_UNESCAPED_SLASHES)
    . 
    "--xyz--";

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt(
        $ch,
        CURLOPT_HTTPHEADER,
        [
        'Authorization Bearer $access_token',
        'Content-Type: multipart/mixed; boundary=xyz;',
        'X-RestLi-Protocol-Version: 2.0.0',
        'X-HTTP-Method-Override: PUT'
    ]);

    $result = curl_exec($ch);
    $error = curl_error($ch);

    curl_close($ch);

尝试用回车 return 翻译每个 \r\n,例如:

curl -X POST 'https://api.linkedin.com/v2/adCreativesV2' \
  -H "X-HTTP-Method-Override: PUT" \
  -H "Content-Type: multipart/mixed; boundary=xyz" \
  -H "X-RestLi-Method: BATCH_PARTIAL_UPDATE" \
  -H "X-RestLi-Protocol-Version: 2.0.0 " \
  --data $'--xyz\r\nContent-Type: application/x-www-form-urlencoded
ids=List(123)
--xyz
Content-Type: application/json

{"entities": {{"123": {"patch": {"$set": {"status": "ACTIVE"}}}}}}
--xyz--'

See here in action

有关更多信息,请参阅 the specs 多部分如何工作

PS: 这不是我第一次在 linkedin 文档中找到 an issue

编辑:

PHP 示例代码:

<?php

$ch = \curl_init();
$url = "https://api.linkedin.com/v2/adCreativesV2";
$parameters = [
    "entities" => [
        [
            [
                "47770196" => [
                    "patch" => [
                        "$set" => [
                            "status" => "ACTIVE",
                        ],
                    ],
                ],
            ],
        ],
],
];

$jsonData = "
--xyz
Content-Type: application/json"
. json_encode($parameters, JSON_UNESCAPED_SLASHES)
.
"--xyz--";

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
[
'Authorization Bearer $access_token',
'Content-Type: multipart/mixed; boundary=xyz;',
'X-RestLi-Protocol-Version: 2.0.0',
'X-HTTP-Method-Override: PUT'
]);

$result = curl_exec($ch);
$error = curl_error($ch);

print_r($result);
print_r($error);


curl_close($ch);

打印:

>php -f src/ln.php
{"serviceErrorCode":65604,"message":"Empty oauth2 access token","status":401}%