Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
79 lines (67 sloc) 2.94 KB
* Copyright 2018 Google Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
// [START vision_product_search_import_product_images]
namespace Google\Cloud\Samples\Vision;
// [START vision_product_search_tutorial_import]
use Google\Cloud\Vision\V1\ProductSearchClient;
use Google\Cloud\Vision\V1\ImportProductSetsGcsSource;
use Google\Cloud\Vision\V1\ImportProductSetsInputConfig;
// [END vision_product_search_tutorial_import]
* Import images of different products in the product set.
* @param string $projectId Your Google Cloud Project ID
* @param string $location Google Cloud compute region name
* @param string $gcsUri Google Cloud Storage URI
function product_set_import($projectId, $location, $gcsUri)
$client = new ProductSearchClient();
# a resource that represents Google Cloud Platform location.
$locationPath = $client->locationName($projectId, $location);
# set the input configuration along with Google Cloud Storage URI
$gcsSource = (new ImportProductSetsGcsSource())
$inputConfig = (new ImportProductSetsInputConfig())
# import the product sets from the input URI
$operation = $client->importProductSets($locationPath, $inputConfig);
$operationName = $operation->getName();
printf('Processing operation name: %s' . PHP_EOL, $operationName);
print('Processing done.' . PHP_EOL);
if ($result = $operation->getResult()) {
$referenceImages = $result->getReferenceImages();
foreach ($result->getStatuses() as $count => $status) {
printf('Status of processing line %d of the csv: ' . PHP_EOL, $count);
# check the status of reference image
# `0` is the code for OK in google.rpc.Code.
if ($status->getCode() == 0) {
$referenceImage = $referenceImages[$count];
printf('name: %s' . PHP_EOL, $referenceImage->getName());
printf('uri: %s' . PHP_EOL, $referenceImage->getUri());
} else {
printf('Status code not OK: %s' . PHP_EOL, $status->getMessage());
print('IMPORTANT: You will need to wait up to 30 minutes for indexing to complete' . PHP_EOL);
} else {
printf('Error: %s' . PHP_EOL, $operation->getError()->getMessage());
// [END vision_product_search_import_product_images]
You can’t perform that action at this time.