CURL PHP中的关键字的谷歌广告API

sg24os4d  于 2022-11-13  发布在  PHP
关注(0)|答案(1)|浏览(171)

我试图为我们的雇主,我有谷歌广告开发商令牌关键字搜索系统,但我无法找到任何CURL或PHP CURL安装指南。
两个参考链接Ad API Examples
Method: customers.generateKeywordIdeas

来自Google文档的示例:

curl -f --request POST "https://googleads.googleapis.com/v${API_VERSION}/customers/${CUSTOMER_ID}/campaignBudgets:mutate" \
--header "Content-Type: application/json" \
--header "developer-token: ${DEVELOPER_TOKEN}" \
--header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \
--header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \
--data "{
'operations': [
  {
    'create': {
      'name': 'My Campaign Budget #${RANDOM}',
      'amountMicros': 500000,
    }
  },
  {
    'create': {
      'name': 'My Campaign Budget #${RANDOM}',
      'amountMicros': 500000,
    }
  }
]
}"

我尝试此代码,但出现错误

<?
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, 'https://googleads.googleapis.com/v11/customers/(MANAGER_CUSTOMER_ID):generateKeywordIdeas');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n\n\"keywordSeed\": {\n    \"keywords\": [\n    \"cofee\"\n  ]\n  }\n}");
    
    $headers = array();
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Login-Customer-Id: (MANAGER_CUSTOMER_ID)';
    $headers[] = 'Developer-Token: DEVELOPER_TOKEN';
    $headers[] = 'Authorization: Bearer (OAUTH_ACCESS_TOKEN)';
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    print_r($result);
    curl_close($ch);

没有任何输出

yzxexxkh

yzxexxkh1#

此示例基于Method: customers.generateKeywordIdeas

试试这个:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://googleads.googleapis.com/v11/customers/${CUSTOMER_ID}:generateKeywordIdeas');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type' => 'application/json',
    'developer-token' => '${DEVELOPER_TOKEN}',
    'login-customer-id' => '${MANAGER_CUSTOMER_ID}',
    'Authorization' => 'Bearer ${OAUTH2_ACCESS_TOKEN}',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{ "geoTargetConstants": [ string ], "language": string, "keywordSeed": {object (KeywordSeed)},}');

$response = curl_exec($ch);

curl_close($ch);

LINK: Handy curl conversion tool
这是我在转换工具中使用的curl代码,用于生成PHP:

curl --request POST "https://googleads.googleapis.com/v11/customers/${CUSTOMER_ID}:generateKeywordIdeas" \
--header "Content-Type: application/json" \
--header "developer-token: ${DEVELOPER_TOKEN}" \
--header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \
--header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \
-d '{ "geoTargetConstants": [ string ], "language": string, "keywordSeed": {object (KeywordSeed)},}'

相关问题