'Google Search Console API, URL Inspection

I want to use the Google Search Console API to check if an url is indexed.

$client = new Google_Client();
$client->setAuthConfig( json_decode( $json, true ));
$scopes = ['https://www.googleapis.com/auth/webmasters','https://www.googleapis.com/auth/webmasters.readonly'];
$client->addScope($scopes);
$searchConsole = new Google_Service_SearchConsole($client);
$urlRequest = new \Google_Service_SearchConsole_InspectUrlIndexRequest();
$urlRequest->setInspectionUrl($url);
$urlRequest->setLanguageCode('fr');
$urlRequest->setSiteUrl('sc-domain:'.$url);
$urlIndex = new \Google_Service_SearchConsole_Resource_UrlInspectionIndex();

The problem is when I try to create an UrlInspectionIndex to make an inspect() with $urlRequest I get an Exception in the constructor of vendor/google/apiclient/src/Service/Resource.php:66

I don't know what those arguments are. Hope anyone would help me, thank you.



Solution 1:[1]

I got it to work like this:

$service = new Google_Service_SearchConsole($client);
$query = new Google_Service_SearchConsole_InspectUrlIndexRequest();
$query->setSiteUrl("https://$domain/");
$query->setInspectionUrl("https://$domain/$page");
$results = $service->urlInspection_index->inspect($query);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1