Linkedin Marketing API 3月31日查询更新 [英] Linkedin Marketing API March 31 queries update

查看:52
本文介绍了Linkedin Marketing API 3月31日查询更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有些人可能知道,Linkedin Marketing API宣布从2021年3月31日开始,他们将开始拒绝不符合新标准的API调用.因此,我开始更新服务.但是,存在这样的问题.文档中给出的示例CURL命令不起作用.相关公告

Some may know, Linkedin Marketing API announced they will begin rejecting API calls not meeting new criteria starting March 31, 2021. So I started updating my service. However, there is such a problem. The sample CURL commands given in the documentation do not work. Related announcement

您以前遇到过这样的问题吗?如果我需要向您展示一些示例:

Have you encountered such a problem before? If I need to show you a few examples:

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的示例可以正常工作,但是在发布请求中使用的标头为: -H Content-Type:multipart/mixed;boundary = xyz; 导致问题.

The examples in which the GET requests mentioned in the documentation are converted to POST work fine, but the header used in post requests: -H Content-Type: multipart / mixed; boundary = xyz; causing the problem.

正如Matteo在下面说的那样,问题出在 \ r \ n 上,但是,我在我的应用程序中使用了PHP CURL.我不确定如何将 \ r \ n 转换为回车符.这是一个用法示例:

As Matteo said below, the problem was at the \r\n But, I'm using PHP CURL in my app. I'm not sure how can I translate \r\n to carriage return. This is a usage example:

    $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);

推荐答案

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

Try translating every \r\n with a carriage return, as example:

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--'

查看此处的操作

有关更多信息,请参见有关规范的内容

For further information see the specs about how multipart work

PS:这不是我第一次在以下内容中发现一个问题linkedin文档

PS: Is not the first time I've found an issue in the linkedin doc

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}%

这篇关于Linkedin Marketing API 3月31日查询更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆