Google Cloud API - Application Default Credentials

前端 未结 5 1331
借酒劲吻你
借酒劲吻你 2021-02-04 07:04

I have the following code, modified from Google\'s documentation:

        $GOOGLE_APPLICATION_CREDENTIALS = \"./[path].json\";
        $_ENV[\"GOOGLE_APPLICATION         


        
5条回答
  •  再見小時候
    2021-02-04 07:34

    Attempt to use the ImageAnnotator like below When running the code, observe that you get an error: Could not construct ApplicationDefaultCredentials

    solution

    putenv("GOOGLE_APPLICATION_CREDENTIALS=/home/netwons/Downloads/AIz.json");
    

    but not work. OS: Ubuntu PHP version: 7.2.4 Package name and version: google/cloud-vision 0.19.1 this is code

    $imageAnnotator = new ImageAnnotatorClient();
    //        $client->setAuthConfig('key.json');
    
            # the name of the image file to annotate
            $fileName = '2.png';
    
            # prepare the image to be annotated
            $image = file_get_contents($fileName);
    
            # performs label detection on the image file
            $response = $imageAnnotator->labelDetection($image);
            $labels = $response->getLabelAnnotations();
    
            if ($labels) {
                echo("Labels:" . PHP_EOL);
                foreach ($labels as $label) {
                    echo($label->getDescription() . PHP_EOL);
                }
            } else {
                echo('No label found' . PHP_EOL);
            }
    

提交回复
热议问题