Reputation: 4717
I am using an application that I downloaded using Composer.
The package has many classes that can be called and utilized. However, when I run the below code, I am getting the following error.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
include 'vendor/autoload.php';
$clarifai = new \DarrynTen\Clarifai\Clarifai('CLARIFAI_API_KEY');
$input = new Input();
$input->setImage('https://samples.clarifai.com/metro-north.jpg')->isUrl();
$inputResult = $clarifai->getInputRepository()->add($input);
echo json_encode($inputResult);
?>
Error:
Warning: include(/var/www/html/vendor/darrynten/clarifai-php/src/Entity): failed to open stream: Not a directory in /var/www/html/ctest.php on line 7
Warning: include(): Failed opening '/var/www/html/vendor/darrynten/clarifai-php/src/Entity' for inclusion (include_path='.:/usr/share/php') in /var/www/html/ctest.php on line 7
Fatal error: Uncaught Error: Class 'Input' not found in /var/www/html/ctest.php:11 Stack trace: #0 {main} thrown in /var/www/html/ctest.php on line 11
The class Input is located at /var/www/html/vendor/darrynten/clarifai-php/src/Entity
which I am including using the include keyword in PHP right after the first include, of no avail.
include 'vendor/autoload.php';
include '/var/www/html/vendor/darrynten/clarifai-php/src/Entity';
Later, I used the following code
$concept = new \DarrynTen\Clarifai\Entity\Concept();
$concept->setId('boscoe')->setValue(true);
$input = new \DarrynTen\Clarifai\Entity\Input();
$input->setImage('https://samples.clarifai.com/puppy.jpeg')->isUrl()
->setConcepts([$concept]);
$inputResult = $clarifai->getInputRepository()->add($input);
on the last line, I am getting this error. (Guzzle related)
Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error:
POST https://api.clarifai.com/v2/inputs
resulted in a400 Bad Request
response: {"status":{"code":10020,"description":"Failure"},"inputs":[{"id":"e25be6bf0a4a4090a774694c016202cb","data":{"image":{"ur (truncated...) in /var/www/html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:111 Stack trace: #0 /var/www/html/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1
Is this also name space related?
Upvotes: 1
Views: 489
Reputation: 4755
I have found a new PHP library that seems to be compatible with new apps in Clarifai created with the new api_key
version: phpfanatic/clarifai
You can easily try to install it via composer:
composer require phpfanatic/clarifai
As dependencies you need to have:
Here you can find the full documentation with quick tutorial or step by step explanation.
Upvotes: 1
Reputation: 916
Eddie from Clarifai here. Sorry you ran into an issue.
I see that you are using an API key. This community library currently only supports our old auth mechanism. All new "apps" in Clarifai are only created with an api_key
as opposed to client_id
and client_secret
.
There's currently a PR open to add support for API keys.
We're hoping to have first class PHP support by the end of the year.
Upvotes: 0