how to use php curl to act with google indexing api

Viewed 28

Can anyone post a complete example of php curl to act with google indexing api with authentication, please?

I tried this code but It shows error 401:

<?php
 $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://searchconsole.googleapis.com/v1/urlInspection/index:inspect',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS =>'{"inspectionUrl":"https://04278.khabarban.com"}
        ',
        CURLOPT_HTTPHEADER => array(
            'Authorization: Bearer acac304372e60f88b5984937e88737f60f67092d',
            'Content-Type: application/json'
        ),
    ));

    $response = curl_exec($curl);
    curl_close($curl);
    echo $response; 
0 Answers
Related