Version:"google/cloud-translate": "^1.13" This is the sample code of the document
use Google\ApiCore\ApiException;
use Google\Cloud\Storage\StorageClient;
use Google\Cloud\Translate\V3\GcsSource;
use Google\Cloud\Translate\V3\Glossary;
use Google\Cloud\Translate\V3\Glossary\LanguageCodesSet;
use Google\Cloud\Translate\V3\GlossaryInputConfig;
use Google\Cloud\Translate\V3\TranslationServiceClient;
require "vendor/autoload.php";
$secret_path = "*****.json";
$projectId = "*****";
putenv("GOOGLE_APPLICATION_CREDENTIALS={$secret_path}");
$location = "us-central1";
$language_codes = ["zh-CN","en"];
$storage = new StorageClient();
$dataContent = [["六","sex"]];
$glossaryId = sprintf("translation%d",rand(1000,9999));
$objectName = $glossaryId.".csv";
try {
$bucket = $storage->bucket("trans_text");
$bucket->upload(getCSVContents($dataContent, $language_codes), [
'name' => $objectName,
'metadata' => ['contentType' => 'text/csv']
]);
$gsutil_uri = sprintf('gs://%s/%s', "trans_text", $objectName);
} catch (\Exception $e) {
var_dump($e->getMessage());
exit();
}
function getCSVContents($data, $header)
{
$output = fopen('php://temp', 'w');
fputcsv($output,$header);
foreach ($data as $v) {
fputcsv($output, $v);
}
rewind($output);
$contents = stream_get_contents($output);
fclose($output);
return $contents;
}
// Create a client.
$translationServiceClient = new TranslationServiceClient();
$formattedParent = $translationServiceClient::locationName($projectId,$location);
$glossaryName = $translationServiceClient::glossaryName($projectId,$location,$glossaryId);
$language_codes_set = new LanguageCodesSet();
$language_codes_set->setLanguageCodes($language_codes);
$gcs_source = (new GcsSource())->setInputUri($gsutil_uri);
$input_config = (new GlossaryInputConfig())->setGcsSource($gcs_source);
$glossary = (new Glossary())->setName($glossaryName)->setInputConfig($input_config)->setLanguageCodesSet($language_codes_set);
try {
$response = $translationServiceClient->createGlossary($formattedParent, $glossary);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
Getting the term list and deleting the term list can be successful, but creating the term list cannot be successful.
The execution result prompt is:
The account permissions Iconfigured are:
The project was working before,but suddenly on July 13th I can't create a glossary.Is there something wrong with my configuration?
I want to know how to deal with this problem.
This is the result returned: { "code": 7, "message": "Error: PERMISSION_DENIED. Job state: FAILED.", "details": [ { "@type": "type.googleapis.com/google.rpc.ResourceInfo", "resourceType": "Cloud Storage file", "resourceName": "gs://trans_text/translation5823.csv" }, { "@type": "type.googleapis.com/google.rpc.DebugInfo", "detail": "generic::permission_denied: Calling Match with file "/bigstore/trans_text/translation5823.csv": generic::permission_denied: Calling GetObjectMetadata with file "/bigstore/trans_text/translation5823.csv": cloud.bigstore.ResponseCode.ErrorCode::ACCESS_DENIED: cloud-ml-translation-worker@prod.google.com does not have storage.objects.get access to the Google Cloud Storage object. Permission 'storage.objects.get' denied on resource (or it may not exist). cloud-ml-translation-worker@prod.google.com does not have storage.objects.get access to the Google Cloud Storage object. Permission 'storage.objects.get' denied on resource (or it may not exist). [google.rpc.error_details_ext] { message: "cloud-ml-translation-worker@prod.google.com does not have storage.objects.get access to the Google Cloud Storage object. Permission \'storage.objects.get\' denied on resource (or it may not exist)." details { [type.googleapis.com/google.rpc.DebugInfo] { stack_entries: "com.google.net.rpc3.client.RpcClientException: APPLICATION_ERROR;cloud.bigstore/FrontendObjectsService.Get;cloud-ml-translation-worker@prod.google.com does not have storage.objects.get access to the Google Cloud Storage object. Permission \'storage.objects.get\' denied on resource (or it may not exist). cloud-ml-translation-worker@prod.google.com does not have storage.objects.get access to the Google Cloud Storage object. Permission \'storage.objects.get\' denied on resource (or it may not exist).;AppErrorCode=1;StartTimeMs=1721132267200;tcp;Deadline(sec)=9.992604092;ResFormat=uncompressed;interceptors={[com.google.cloud.bigstore.common.LatencyCollectingInterceptor;com.google.frameworks.debug.sherlog.core.rpcutil.Stubby3ClientInterceptor];overrides={}};ServerTimeSec=0.277276674;LogBytes=256;Non-FailFast;EffSecLevel=strong_privacy_and_integrity;ReqFormat=uncompressed;ReqID=1e86c8901c30e67b;GlobalID=fe5b6149cadcbe0b;Server=[::1]:14005" stack_entries: "com.google.net.rpc3.client.RpcStub.startBlockingRpcInternal(RpcStub.java:571)" stack_entries: "com.google.net.rpc3.client.RpcStub.startBlockingRpc(RpcStub.java:471)" stack_entries: "com.google.cloud.bigstore.proto.BackendObjectsService$Stub.get(BackendObjectsService.java:610)" stack_entries: "com.google.cloud.bigstore.api.common.LampreyServiceBase.call(LampreyServiceBase.java:56)" stack_entries: "com.google.cloud.bigstore.api.common.BigstoreFrontendObjectsServiceImpl.call(BigstoreFrontendObjectsServiceImpl.java:44)" stack_entries: "com.google.cloud.bigstore.api.common.BigstoreFrontendObjectsServiceImpl.get(BigstoreFrontendObjectsServiceImpl.java:81)" stack_entries: "com.google.cloud.bigstore.api.stubby.BigstoreStubbyImpl.lambda$getObjectMetadata$17(BigstoreStubbyImpl.java:1083)" stack_entries: "com.google.cloud.bigstore.api.common.CallbackRequestHandler.handleCallbackRequest(CallbackRequestHandler.java:276)" stack_entries: "com.google.cloud.bigstore.api.common.CallbackRequestHandler.handleCallbackRequest(CallbackRequestHandler.java:144)" stack_entries: "com.google.cloud.bigstore.api.stubby.BigstoreStubbyImpl.getObjectMetadata(BigstoreStubbyImpl.java:1071)" stack_entries: "com.google.cloud.bigstore.api.common.ProxyDelegatorBase.callAndRecordLatency(ProxyDelegatorBase.java:110)" stack_entries: "com.google.cloud.bigstore.api.stubby.StubbyProxyBase.call(StubbyProxyBase.java:159)" stack_entries: "com.google.cloud.bigstore.api.stubby.BigstoreStubbyProxy.getObjectMetadata(BigstoreStubbyProxy.java:403)" stack_entries: "com.google.cloud.bigstore.isolation.RpcReceiver.lambda$processRequestAsync$1(RpcReceiver.java:198)" stack_entries: "com.google.cloud.bigstore.isolation.AsyncExecutor.lambda$submit$0(AsyncExecutor.java:213)" stack_entries: "com.google.common.context.ContextRunnable.runInContext(ContextRunnable.java:83)" stack_entries: "io.grpc.Context.run(Context.java:536)" stack_entries: "com.google.tracing.GenericContextCallback.runInInheritedContext(GenericContextCallback.java:75)" stack_entries: "com.google.common.context.ContextRunnable.run(ContextRunnable.java:74)" stack_entries: "java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)" stack_entries: "java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)" stack_entries: "java.base/java.lang.Thread.run(Unknown Source)" } } } [blobstore2.GcsErrorDetails] { xml_code: "AccessDenied" msg: "cloud-ml-translation-worker@prod.google.com does not have storage.objects.get access to the Google Cloud Storage object. Permission \'storage.objects.get\' denied on resource (or it may not exist)." http_code: 403 details { first: "Details" second: "cloud-ml-translation-worker@prod.google.com does not have storage.objects.get access to the Google Cloud Storage object. Permission \'storage.objects.get\' denied on resource (or it may not exist)." } debug_info: "cloud-ml-translation-worker@prod.google.com does not have storage.objects.get access to the Google Cloud Storage object. Permission \'storage.objects.get\' denied on resource (or it may not exist). cloud-ml-translation-worker@prod.google.com does not have storage.objects.get access to the Google Cloud Storage object. Permission \'storage.objects.get\' denied on resource (or it may not exist)." } [cloud.bigstore.GcsLatencyInfo] { requests { method: "/BackendObjectsService.Get" deadline { seconds: 9 nanos: 986781918 } start { seconds: 1721132267 nanos: 201421144 } end { seconds: 1721132267 nanos: 477976911 } status { code: 1 space: "cloud.bigstore.ResponseCode.ErrorCode" message: "cloud-ml-translation-worker@prod.google.com does not have storage.objects.get access to the Google Cloud Storage object. Permission \'storage.objects.get\' denied on resource (or it may not exist). cloud-ml-translation-worker@prod.google.com does not have storage.objects.get access to the Google Cloud Storage object. Permission \'storage.objects.get\' denied on resource (or it may not exist)." canonical_code: 7 } } requests { method: "/BucketMdService.LookupBucket" deadline { seconds: 4 nanos: 999962410 } start { seconds: 1721132267 nanos: 270744966 } end { seconds: 1721132267 nanos: 273039106 } status { } metadata_spanner_stats { read_walltime_millis: 0 read_cpu_millis: 0 read_scheduler_delay_millis: 0 read_throttle_delay_millis: 0 read_per_service_limit_queue_delay_millis: 0 read_locking_delay_millis: 0 read_client_overhead_delay_millis: 0 read_client_flow_control_delay_millis: 0 read_io_delay_millis: 0 } elapsed_time_isolator_metrics { } sunspot_verdict: VERDICT_CAT_UNKNOWN } requests { method: "/ObjectMdService.LookupObject" deadline { seconds: 4 nanos: 999962920 } start { seconds: 1721132267 nanos: 270744806 } end { seconds: 1721132267 nanos: 276720385 } status { } metadata_spanner_stats { read_walltime_millis: 0 read_cpu_millis: 0 read_scheduler_delay_millis: 0 read_throttle_delay_millis: 0 read_per_service_limit_queue_delay_millis: 0 read_locking_delay_millis: 0 read_client_overhead_delay_millis: 0 read_client_flow_control_delay_millis: 0 read_io_delay_millis: 0 slice_keys: "1:g5612_43043490" } elapsed_time_isolator_metrics { } sunspot_verdict: VERDICT_CAT_UNAVAILABLE } requests { method: "/AccessService.CheckGetObject" deadline { seconds: 9 nanos: 838916510 } start { seconds: 1721132267 nanos: 277024225 } end { seconds: 1721132267 nanos: 410471326 } status { } } slice_keys: "1:g5612_43043490" } [google.rpc.error_details_ext] { message: "cloud-ml-translation-worker@prod.google.com does not have storage.objects.get access to the Google Cloud Storage object. Permission \'storage.objects.get\' denied on resource (or it may not exist)." }; Match result: fail [google.rpc.error_details_ext] { message: "cloud-ml-translation-worker@prod.google.com does not have storage.objects.get access to the Google Cloud Storage object. Permission \'storage.objects.get\' denied on resource (or it may not exist)." }" } ] }
I had the same problem, just add storage.objects.get
permissions to the cloud-ml-translation-worker@prod.google.com
account on the IAM service.
E.g.
PROJECT="..."
USER="cloud-ml-translation-worker@prod.google.com"
ROLE="roles/storage.objectViewer"
gcloud projects add-iam-policy-binding ${PROJECT} \
--member=user:${USER} \
--role=${ROLE}
roles/storage.objectViewer
is one of the predefined IAM roles for Cloud Storage that includes storage.objects.get