google-api-php-client icon indicating copy to clipboard operation
google-api-php-client copied to clipboard

[reasonPhrase:GuzzleHttp\Psr7\Response:private] => Forbidden

Open HeartDisk opened this issue 1 year ago • 3 comments

I am trying to index url using php (CodeIgniter 4) My Code Below.

namespace App\Libraries; use Google_Client; use GuzzleHttp; use GuzzleHttp\Client; use CodeIgniter\HTTP;

require_once ROOTPATH.'/vendor/google/apiclient-services/autoload.php'; class Google { // This function converts a string into slug format public function add_to_index($url) { $googleCli = new Google_Client();
$googleCli->setAuthConfig(MY_JSON_FILE'); $googleCli->addScope('https://www.googleapis.com/auth/indexing'); // Get a Guzzle HTTP Client $httpClient = $googleCli->authorize(); $endpoint = 'https://indexing.googleapis.com/v3/urlNotifications:publish'; // Define contents here. The structure of the content is described in the next step. $content = '{ "url": "'.$url.'", "type": "URL_UPDATED" }'; $response = $httpClient->post($endpoint, [ 'body' => $content ]); return $response; } }

its showing error

GuzzleHttp\Psr7\Response Object ( [reasonPhrase:GuzzleHttp\Psr7\Response:private] => Forbidden [statusCode:GuzzleHttp\Psr7\Response:private] => 403 [headers:GuzzleHttp\Psr7\Response:private] => Array ( [Vary] => Array ( [0] => X-Origin [1] => Referer [2] => Origin,Accept-Encoding )

        [Content-Type] => Array
            (
                [0] => application/json; charset=UTF-8
            )

        [Date] => Array
            (
                [0] => Tue, 05 Mar 2024 08:23:16 GMT
            )

        [Server] => Array
            (
                [0] => ESF
            )

        [Cache-Control] => Array
            (
                [0] => private
            )

        [X-XSS-Protection] => Array
            (
                [0] => 0
            )

        [X-Frame-Options] => Array
            (
                [0] => SAMEORIGIN
            )

        [X-Content-Type-Options] => Array
            (
                [0] => nosniff
            )

        [Alt-Svc] => Array
            (
                [0] => h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
            )

        [Accept-Ranges] => Array
            (
                [0] => none
            )

        [Transfer-Encoding] => Array
            (
                [0] => chunked
            )

    )

[headerNames:GuzzleHttp\Psr7\Response:private] => Array
    (
        [vary] => Vary
        [content-type] => Content-Type
        [date] => Date
        [server] => Server
        [cache-control] => Cache-Control
        [x-xss-protection] => X-XSS-Protection
        [x-frame-options] => X-Frame-Options
        [x-content-type-options] => X-Content-Type-Options
        [alt-svc] => Alt-Svc
        [accept-ranges] => Accept-Ranges
        [transfer-encoding] => Transfer-Encoding
    )

[protocol:GuzzleHttp\Psr7\Response:private] => 1.1
[stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
    (
        [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #220
        [size:GuzzleHttp\Psr7\Stream:private] => 
        [seekable:GuzzleHttp\Psr7\Stream:private] => 1
        [readable:GuzzleHttp\Psr7\Stream:private] => 1
        [writable:GuzzleHttp\Psr7\Stream:private] => 1
        [uri:GuzzleHttp\Psr7\Stream:private] => php://temp
        [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
            (
            )

    )

)

HeartDisk avatar Mar 05 '24 08:03 HeartDisk

I've the same issue.

svgta1 avatar Mar 24 '24 19:03 svgta1

I've found the solution for me, verify for you : Web Search Indexing API was not activated.

Now, it's work.

svgta1 avatar Mar 24 '24 19:03 svgta1

I've found the solution for me, verify for you : Web Search Indexing API was not activated.

Now, it's work.

in my case it's activated and verified still same issue

HeartDisk avatar Mar 29 '24 11:03 HeartDisk