Customer IDs: customers/7114018995 API Error: The caller does not have permission

50 views
Skip to first unread message

surendra yadav

unread,
Nov 29, 2023, 4:39:34 PM11/29/23
to Google Ads API and AdWords API Forum
Hello Google Ads API Support, 

I need support for resolved this below issue.

Customer IDs: customers/8165191974 API Error: The caller does not have permission
Customer IDs: customers/7114018995 API Error: The caller does not have permission
Customer IDs: customers/9172587698 API Error: The caller does not have permission
Customer IDs: customers/9232339892 API Error: The caller does not have permission

What is my task:

1. Get user or audience list
2. Add/Remove the Email or Phone in the exiting list 

Below is the my PHP code or you can check the attached PHP code of file

$customer_id = str_replace('customers/', '', $customerResourceName);
$api_version = 'v15';                    
                      
// Google Ads API endpoint URL for searching

// Construct the query to search for audiences
$query = 'SELECT audience.id, audience.name FROM audience WHERE campaign.id = ' . $customer_id;

// Set up cURL options
$curl_options = [
    CURLOPT_URL => $api_url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $new_access_token,
        'Content-Type: application/json',
        'developer-token: ' . $developer_token,
        'login-customer-id: ' . $customer_id,
    ],
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => json_encode(['query' => $query]),
];

// Initialize cURL session
$ch = curl_init();
curl_setopt_array($ch, $curl_options);

// Execute the cURL request and get the response
$response = curl_exec($ch);

// Check for errors
if (curl_errno($ch)) {
    echo 'cURL Error: ' . curl_error($ch);
} else {
    // Decode and print the response
    $decoded_response = json_decode($response, true);

    // Check if the response contains an error
    if (isset($decoded_response['error'])) {
        echo 'API Error: ' . $decoded_response['error']['message'];
    } else {
        // Print the audience list if available
        if (isset($decoded_response['results'])) {
            foreach ($decoded_response['results'] as $result) {
                echo 'Audience ID: ' . $result['audience']['id'] . PHP_EOL;
                echo 'Audience Name: ' . $result['audience']['name'] . PHP_EOL;
              
                $audience_id = $result['audience']['id'];

                // Example list of user information (hashed email or phone number)
                $users = [
                    ['email' => hash('sha256', 's...@gmail.com.com')],
                    ['email' => hash('sha256', 'sk...@gmail.com.com')],
                    // Add more users as needed
                ];

                // Google Ads API endpoint URL for adding members to an audience

                // Set up cURL options
                $curl_options = [
                    CURLOPT_URL => $api_url,
                    CURLOPT_RETURNTRANSFER => true,
                    CURLOPT_CUSTOMREQUEST => 'POST',
                    CURLOPT_POSTFIELDS => json_encode(['membersList' => $users]),
                    CURLOPT_HTTPHEADER => [
                        'Authorization: Bearer ' . $api_key,
                        'Content-Type: application/json',
                    ],
                ];

                // Initialize cURL session
                $ch = curl_init();
                curl_setopt_array($ch, $curl_options);

                // Execute the cURL request and get the response
                $response = curl_exec($ch);

                // Check for errors
                if (curl_errno($ch)) {
                    echo 'cURL Error: ' . curl_error($ch);
                } else {
                    // Decode and print the response
                    $decoded_response = json_decode($response, true);
                    print_r($decoded_response);
                }

                // Close cURL session
                curl_close($ch);

            }
        } else {
            echo 'No audiences found for the specified customer.';
        }
    }
}

// Close cURL session
curl_close($ch);


Thanks & Regards
Surendra Yadav
9958263028
google-support.php
Reply all
Reply to author
Forward
0 new messages