PHP Include - error in opening the stream - php

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 a 400
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?

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:
PHP - 5.6, 7.0 - May work with ealier version, untested at this time.
cURL - *
Clarifai API Key - clarifai
PHPUnit - to run tests (optional).
Here you can find the full documentation with quick tutorial or step by step explanation.

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.

Related

Agent Library at Laravel. What's Wrong?

what's up?
I found this problem: I initiate a new project from 0, installing Laravel with composer:
composer create-project laravel/laravel --prefer-dist Blog
The following step was to add the Agent library https://github.com/jenssegers/agent.
composer require jenssegers/agent
This is the first library that I have ever used on Laravel and I'm not sure if I did it correctly. I added the line codes mentioned in the Agent's README.md at the config/app.php. After it, I went to public/index.php at my project and add the following lines to test it:
use Jenssegers\Agent\Facades\Agent;
$agent = new Agent();
Infortunally it didn't work and I had received the following error: Fatal error: Uncaught Error: Class "Jenssegers\Agent\Facades\Agent" not found in C:\xampp\htdocs\BlogBRU\public\index.php:7 Stack trace: #0 {main} thrown in C:\xampp\htdocs\BlogBRU\public\index.php on line 7. The line 7 correspond to $agent = new Agent();
I already tried to modify the use ... for:
use use Jenssegers\Agent\Facades;
use Jenssegers\Agent\Agent;
But it doesn't work.
I will appreciate it if you could help me. This is taking all my time!

I used the TwitterOAuth library and got this error

Fatal error: Uncaught Error: Class 'Composer\CaBundle\CaBundle' not found in
C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php:572 Stack trace:
#0 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(620): Abraham\TwitterOAuth\TwitterOAuth->curlOptions()
#1 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(557): Abraham\TwitterOAuth\TwitterOAuth->request('https://api.twi...', 'GET', 'Authorization: ...', Array, false)
#2 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(490): Abraham\TwitterOAuth\TwitterOAuth->oAuthRequest('https://api.twi...', 'GET', Array, false)
#3 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(467): Abraham\TwitterOAuth\TwitterOAuth->makeRequests('https://api.twi...', 'GET', Array, false)
#4 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(232): Abraham\TwitterOAuth\TwitterOAuth->http('GET', 'h in C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php on line 572
I'm using it for the first time, so checked the TwitterOAuth.php file and line 572 then vscode says the CaBundle is undefined Type Undefined type 'Composer\CaBundle\CaBundle'. , I tried downloading the file over and over again but the same error.
I had the exact same problem following the instructions on here.
It turns out I wasn't including the right autoload. For those coming across the same problem:
Install composer locally on your directory as per these instructions.
Run php composer require abraham/twitteroauth.
Run php composer install.
Make sure to include the right path to the composer autoloader file, not the package autoloader, in your PHP code require "vendor/autoload.php";.
In each file that you will be using the package, don't forget to include the line use Abraham\TwitterOAuth\TwitterOAuth as TwitterOAuth;, so that you can use $foo = new TwitterOAuth();
I hope this helps those who might be new to composer like me.

How to use logger without composer and namespaces?

I am trying to install Mangopay https://github.com/Mangopay/mangopay2-php-sdk, but the recommended solution of installing it without composer doesn't work. I used this line:
require_once "mango/mangopay2-php-sdk-2.11.0/MangoPay/Autoloader.php";
$api = new MangoPay\MangoPayApi();
The file get's loaded, but I get the following error:
Fatal error: Uncaught Error: Class 'Psr\Log\NullLogger' not found in
/usr/local/apache2/htdocs/MangoPay/MangoPayApi.php:223 Stack trace:
#0 /usr/local/apache2/htdocs/pay.php(5): MangoPay\MangoPayApi-
>__construct() #1 {main} thrown in
/usr/local/apache2/htdocs/MangoPay/MangoPayApi.php on line 223
The issue is with the logger, which I manually downloaded and copied into the directory but it still doesn't work. I am only asking here because I am not getting any response from the developers.
Any help with manually installing the logger and getting the namespace to work with mangopay is welcome.

How to use vkapi library PHP

Already installed library using composer
Я уже установил библиотеку через composer
composer require vkcom/vk-php-sdk
But cant initializate it by
однако не выходит её инициализировать через
$vk = new VKApiClient();
Recieve error
Получаю ошибку
Fatal error: Uncaught Error: Class 'VKApiClient' not found in E:\OSPanel\domains\localhost\albom.php:2 Stack trace: #0 {main} thrown in E:\OSPanel\domains\localhost\albom.php on line 2
Directory hierarchy image
Изображение иерархии директорий
I already tried method below:
Также я пробовал способ ниже:
$vk = new \vkapi\src\VK\Client\VKApiClient();
But receive error:
Но получаю ошибку:
Fatal error: Uncaught Error: Class 'vkapi\src\VK\Client\VKApiClient' not found in E:\OSPanel\domains\localhost\albom.php:2 Stack trace: #0 {main} thrown in E:\OSPanel\domains\localhost\albom.php on line 2
Tried use require for composer autoload file, but it still doesnt works well
Уже пробовал использовать require для автозагрузочного файла composer'a, но это всё равно не работает
require '.\vendor\autoload.php';
$vk = new VKApiClient();
Recieve error
Получаю ошибку
Fatal error: Uncaught Error: Class 'VKApiClient' not found in E:\OSPanel\domains\localhost\albom.php:3 Stack trace: #0 {main} thrown in E:\OSPanel\domains\localhost\albom.php on line 3
There are different points here.
First, VKApiClient's namespace is not \vkapi\src\VK\Client\. You can open a file and read the code. It doesn't contain src at all, it does contain namespace VK\Client, so you can initialize client this way
$vk = new \VK\Client\VKApiClient();
Second, you have to include source file. Composer does it via autoload.php. If is not actual somehow, try php composer dump-autoload to refresh autoload file.
Actually, you'd better use English only. Russian SO is here. Have you tried to ask your question there? Though audience is much greater here, I prefer English SO rather that Russian.

Google api php client

I'm trying to implement the google analytics API on localhost site using xampp on Mac OS.
but Im getting this error:
Fatal error: Uncaught Exception: This library must be installed via composer or by downloading the full package. See the instructions at https://github.com/google/google-api-php-client#installation. in /Applications/XAMPP/xamppfiles/htdocs/ga-api/google-api-php-client/autoload.php:14 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/ga-api/index.php(4): require_once() #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/ga-api/google-api-php-client/autoload.php on line 14
Can anyone help me with this?
Given that you installed the library using Composer, it will be installed to vendor and will be available in the autoload.php that Composer generates.
I will require_once DIR. '/vendor/autoload.php'; in index.php (preferred) or where I need to instantiate the GoogleClient class.
Ensure that the path to client credentials are rightly referenced when you set auth config like so:
Google_Client->setAuthConfig($pathToCredentials)
Reference:
Setting auth credentials:
https://github.com/google/google-api-php-client#authentication-with-oauth
Autoloading classes:
https://getcomposer.org/doc/01-basic-usage.md#autoloading

Categories