Jump to content

Yii2 Google Cloud Vision API Authentication Problem


PHPLazy

Recommended Posts

Hey Guys.

 

I want to implement google cloud vision api for recognise the image. Everything installed fine, I'm getting the error 

Google\Cloud\Core\Exception\ServiceException
{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"status": "PERMISSION_DENIED"
}
}
1. in C:\xampp\htdocs\vofms\vendor\google\cloud-core\src\RequestWrapper.php at line 336
327328329330331332333334335336337338339340341342343344345                                case 504:
                $exception = Exception\DeadlineExceededException::class;
                break;
 
            default:
                $exception = Exception\ServiceException::class;
                break;
        }
 
        return new $exception($this->getExceptionMessage($ex), $ex->getCode(), $ex);
    }
 
    /**
     * Gets the exception message.
     *
     * @param \Exception $ex
     * @return string
     */
    private function getExceptionMessage(\Exception $ex)
                
2. in C:\xampp\htdocs\vofms\vendor\google\cloud-core\src\RequestWrapper.php at line 189 – Google\Cloud\Core\RequestWrapper::convertToGoogleException(GuzzleHttp\Exception\ClientException)
183184185186187188189190191192193194195                            try {
            return $backoff->execute($this->httpHandler, [
                $this->applyHeaders($request),
                $this->getRequestOptions($options)
            ]);
        } catch (\Exception $ex) {
            throw $this->convertToGoogleException($ex);
        }
    }
 
    /**
     * Deliver the request asynchronously.
     *
                
3. in C:\xampp\htdocs\vofms\vendor\google\cloud-core\src\RestTrait.php at line 96 – Google\Cloud\Core\RequestWrapper::send(GuzzleHttp\Psr7\Request, [])
90919293949596979899100101102                     
        try {
            return json_decode(
                $this->requestWrapper->send(
                    $this->requestBuilder->build($resource, $method, $options),
                    $requestOptions
                )->getBody(),
                true
            );
        } catch (NotFoundException $e) {
            if ($whitelisted) {
                throw $this->modifyWhitelistedError($e);
            }
                
4. in C:\xampp\htdocs\vofms\vendor\google\cloud-vision\src\Connection\Rest.php at line 59 – Google\Cloud\Vision\Connection\Rest::send('images', 'annotate', ['requests' => [['image' => ['content' => '/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBD...'], 'features' => [['type' => 'FACE_DETECTION']]]]])
535455565758596061                     
    /**
     * @param array $args
     */
    public function annotate(array $args)
    {
        return $this->send('images', 'annotate', $args);
    }
}
                
5. in C:\xampp\htdocs\vofms\vendor\google\cloud-vision\src\VisionClient.php at line 272 – Google\Cloud\Vision\Connection\Rest::annotate(['requests' => [['image' => ['content' => '/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBD...'], 'features' => [['type' => 'FACE_DETECTION']]]]])
266267268269270271272273274275276277278                            foreach ($images as $image) {
            $requests[] = $image->requestObject();
        }
 
        $res = $this->connection->annotate([
            'requests' => $requests
        ] + $options);
 
        $annotations = [];
        if (isset($res['responses'])) {
            foreach ($res['responses'] as $response) {
                $annotations[] = new Annotation($response);
            }
                
6. in C:\xampp\htdocs\vofms\vendor\google\cloud-vision\src\VisionClient.php at line 229 – Google\Cloud\Vision\VisionClient::annotateBatch([Google\Cloud\Vision\Image], [])
223224225226227228229230231232233234235                         * @param  Image $image The image to annotate
     * @param  array $options Configuration options
     * @return Annotation
     */
    public function annotate(Image $image, array $options = [])
    {
        $res = $this->annotateBatch([$image], $options);
        return $res[0];
    }
 
    /**
     * Annotate a set of images.
     *
                
7. in C:\xampp\htdocs\vofms\frontend\themes\admin_lte\site\index.php at line 22 – Google\Cloud\Vision\VisionClient::annotate(Google\Cloud\Vision\Image)
16171819202122232425262728                     
$image = $vision->image(
    fopen('C:\xampp\htdocs\vofms\frontend\themes\admin_lte\images\1.jpg', 'r'),
    ['faces']
);
 
$annotation = $vision->annotate($image);
 
// Determine if the detected faces have headwear.
foreach ($annotation->faces() as $key => $face) {
    if ($face->hasHeadwear()) {
        echo "Face $key has headwear.\n";
    }
                
8. in C:\xampp\htdocs\vofms\vendor\yiisoft\yii2\base\View.php at line 348 – require('C:\xampp\htdocs\vofms\frontend\t...')
9. in C:\xampp\htdocs\vofms\vendor\yiisoft\yii2\base\View.php at line 257 – yii\base\View::renderPhpFile('C:\xampp\htdocs\vofms\frontend\t...', ['dataProvider' => yii\data\ActiveDataProvider])
10. in C:\xampp\htdocs\vofms\vendor\yiisoft\yii2\base\View.php at line 156 – yii\base\View::renderFile('C:\xampp\htdocs\vofms\frontend\v...', ['dataProvider' => yii\data\ActiveDataProvider], frontend\controllers\SiteController)
11. in C:\xampp\htdocs\vofms\vendor\yiisoft\yii2\base\Controller.php at line 384 – yii\base\View::render('index', ['dataProvider' => yii\data\ActiveDataProvider], frontend\controllers\SiteController)
12. in C:\xampp\htdocs\vofms\frontend\controllers\SiteController.php at line 89 – yii\base\Controller::render('index', ['dataProvider' => yii\data\ActiveDataProvider])
83848586878889909192939495                            $dataProvider = new ActiveDataProvider([
            'query' => Offenses::find(),
        ]);
 
        return $this->render('index', [
            'dataProvider' => $dataProvider,
        ]);
    }
 
    /**
     * Displays a single Offenses model.
     * @param integer $id
     * @return mixed
                
13. frontend\controllers\SiteController::actionIndex()
14. in C:\xampp\htdocs\vofms\vendor\yiisoft\yii2\base\InlineAction.php at line 57 – call_user_func_array([frontend\controllers\SiteController, 'actionIndex'], [])
15. in C:\xampp\htdocs\vofms\vendor\yiisoft\yii2\base\Controller.php at line 157 – yii\base\InlineAction::runWithParams(['r' => 'site/index'])
16. in C:\xampp\htdocs\vofms\vendor\yiisoft\yii2\base\Module.php at line 528 – yii\base\Controller::runAction('index', ['r' => 'site/index'])
17. in C:\xampp\htdocs\vofms\vendor\yiisoft\yii2\web\Application.php at line 103 – yii\base\Module::runAction('site/index', ['r' => 'site/index'])
18. in C:\xampp\htdocs\vofms\vendor\yiisoft\yii2\base\Application.php at line 386 – yii\web\Application::handleRequest(yii\web\Request)
19. in C:\xampp\htdocs\vofms\frontend\web\index.php at line 17 – yii\base\Application::run()
11121314151617                        require _DIR_ . '/../../common/config/main.php',
    require _DIR_ . '/../../common/config/main-local.php',
    require _DIR_ . '/../config/main.php',
    require _DIR_ . '/../config/main-local.php'
);
 
(new yii\web\Application($config))->run()
Quote

 

Where I can set GOOGLE_APPLICATION_CREDENTIALS environment variable in Yii2 framework.

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.