Google ads api for keywordideas in CURL PHP
I try to make a keyword searches system for our employ and i have google ads developer token But I cannot able to find any CURL or PHP CURL setup guide.
Two reference links Ad API Examples
Method: customers.generateKeywordIdeas
An example from Google's documentation:
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, } } ] }"
I try this code but got Error
<? $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);
I'm not getting any output
This example is based on Method: customers.generateKeywordIdeas
Try this:
$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
This is the curl code I used in the conversion tool to generate the 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)},}'developers.google.com/google-ads/api/rest/reference/rest/v9/… Please tell us who i can pass country in {"geoTargetConstants":[],"keywordSeed":{"keywords":["seo"]} ,"language": string} Please tell us how I can put the country in geoTargetConstants and language I try to download developers.google.com/adwords/api/docs/appendix/geotargeting .csv but I cannot able to find any example of how to implement geoTargetConstants and language
I updated the PHP curl in my answer. Google does not make it easy. I spent hours working on this.
Can you please tell me an example of any keyword with a US location with English language