首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Google ads api在CURL PHP中的关键字代码

Google ads api在CURL PHP中的关键字代码
EN

Stack Overflow用户
提问于 2022-10-03 08:20:34
回答 1查看 132关注 0票数 0

我试图为我们的雇用做关键字搜索系统,我有谷歌广告开发商令牌,但我无法找到任何卷曲或PHP卷曲设置指南。

两个参考链接API示例

方法: customers.generateKeywordIdeas

谷歌文档中的一个例子:

代码语言:javascript
运行
复制
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,
    }
  }
]
}"

我尝试了这段代码,但得到了错误

代码语言:javascript
运行
复制
    <?
    
    $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);

我没有得到任何输出

EN

回答 1

Stack Overflow用户

发布于 2022-10-07 04:33:49

此示例基于方法: customers.generateKeywordIdeas

尝试如下:

代码语言:javascript
运行
复制
$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);

链接:方便的卷曲转换工具

这是我在转换工具中用来生成PHP的curl代码:

代码语言:javascript
运行
复制
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)},}'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73932780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档