How to use vkapi library PHP - 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.

Related

What would prevent a PHP die() from working? On my computer die() is not working

This is on MacOS with PHP 8.1.10 installed via homebrew ...
Just a blank index.php code in it with only this code ...
<?php
die('We Should Just Die Here');
throw new \RuntimeException('This exception should never be seen');
?>
And .. render in my browser to see ...
<br />
<b>Fatal error</b>: Uncaught RuntimeException: This exception should never be seen in /path/to/public/index.php:4
Stack trace:
#0 /Users/my-user/.composer/vendor/laravel/valet/server.php(234): require()
#1 {main}
thrown in <b>/path/to/public/index.php</b> on line <b>4</b><br />
Same story if I run it command line (taking valet out of the equation) ..
$ php index.php
Fatal error: Uncaught RuntimeException: This exception should never be seen in /path/to/public/index.php:4
Stack trace:
#0 {main}
thrown in /path/to/public/index.php on line 4
I have already tried ...
Upgrading PHP
Re-installed Valet
Composer updating everything
In my roughly 800 years of writing PHP code I have never seen anything like this. Please if anyone has any help I'm interested.
I've found it. I installed the php-uopz extension a while back. I had completely forgotten about that.
pecl uninstall uopz fixed this for me.
Thank you for the rubber ducking stack overflow ;P

PHP code run in terminal but not working in chrome

I have used pdf-to-image to build my new package. and I got some problem here:
<?php
// die(echo getenv('HOME'););
require_once(__DIR__.'/vendor/autoload.php');
$fileone = realpath('demo.pdf');
$pdf = new Spatie\PdfToImage\Pdf($fileone);
$pdf->saveImage(__DIR__.'upload/');
?>
I required it into index file but I can't run this code on Chrome but it working when I run by terminal, how can I fix it?
UPDATE Adding error shared in comments:
Fatal error: Uncaught ImagickException: Failed to read the file in /opt/lampp/htdocs/pdf2Image/vendor/spatie/pdf-to-image/src/Pdf.php:44 Stack trace: #0 /opt/lampp/htdocs/pdf2Image/vendor/spatie/pdf-to-image/src/Pdf.php(44): Imagick->__construct('/opt/lampp/htdo...') #1 /opt/lampp/htdocs/pdf2Image/index.php(6): Spatie\PdfToImage\Pdf->__construct('/opt/lampp/htdo...') #2 {main} thrown in /opt/lampp/htdocs/pdf2Image/vendor/spatie/pdf-to-image/src/Pdf.php on line 44

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.

PHP Include - error in opening the stream

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.

Cannot create phar

I am trying to learn how to create phars and i am getting this error and have no clue how to fix it. Any ideas?
Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Cannot create phar '/myapp/build/myapp.phar', file extension (or combination) not recognised or the directory does not exist' in /Volumes/www/vhosts/myapp/create-phar.php:11
Stack trace:
#0 /Volumes/www/vhosts/myapp/create-phar.php(11): Phar->__construct('/myapp/build/my...', 256, 'myapp.phar')
#1 {main}
thrown in /Volumes/www/vhosts/myapp/create-phar.php on line 11
I am following the code form this page: packaging your app with phar
Use the full path for windows like
$srcRoot = getcwd() . '/src';
$buildRoot = getcwd() . '/build';
I've been following the same article and the problem are the paths or how they are defined in the first couple of lines, here is what I did:
$srcRoot = "src/";
$buildRoot = "build/";
This solution is for Ubuntu 12.04.3 LTS

Categories