Undefined variable notice when trying to use Spotify API PHP Wrapper - php

I hope you are well. I am brand new to coding and have spent a lot of time trying to find a solution to my question, without much luck.
I was trying to utilize Spotify's API with PHP but ran into thus far unsurmountable hurdles. Please see steps taken below:
1.) I downloaded the Spotify PHP Wrapper library here https://github.com/jwilsson/spotify-web-api-php, and saved it in the same directory as my app. I then created a composer.json file as below :
{
"require": {
"jwilsson/spotify-web-api-php": "^1.0.0"
}
}
2.) After creating and saving the composer.json file, I ran "composer install" in terminal in the same directory as where the composer.json file was stored, which led to the creation of a composer.lock file and a vendor folder.
3.) I then moved the composer.lock, composer.json and vendor folders to my online hosting service (ecowebhosting) via firebug, so that I can run and test the code. I also created a .php file that I moved to the server as well.
In my .php page, i declared the required files as such (below) and ran a sample query form the Spotify API PHP Wrapper documentation on github, to confirm whether or not I successfully loaded the library (the autoload.php folder was automatically created in the "Vendor" folder, after I performed step 2 above):
require 'vendor/autoload.php';
$tracks = $api->getAlbumTracks('1oR3KrPIp4CbagPa3PhtPp');
print_r ($tracks);
When I run the code above, I get the error below:
Notice: Undefined variable: api in /home/sites/amanka.com/public_html/content/SmallApps/ListeningPod/home.php on line 8 Fatal error: Call to a member function getAlbumTracks() on a non-object in /home/sites/amanka.com/public_html/content/SmallApps/ListeningPod/home.php on line 8
This error causes me to think that I have not installed the Library correctly. Please any ideas where I might be going wrong?
Thanks a lot

Related

how does composer for binance API for PHP work?

I try to get this done from github.
https://github.com/binance-exchange/php-binance-api
I installed Xampp (latest version: 7.2.3) on a win 10 machine. Xampp is running. (at least not mysql, because it has an error while starting, but mysql is not needed).
I downloaded the files from github and puttet them into my htdocs in a new folder called "binance".
I downloaded the install-file for composer from here: https://getcomposer.org/doc/00-intro.md#installation-windows
Installed it and choosed the php.exe out of my xampp folder inside the installation-process.
Composer starts out of the console, and it works.
I put this command into the cmd:
php composer.phar require "jaggedsoft/php-binance-api #dev"
It installs some folders and files, but not into my project-directory. It downloads and installs it into "user/vendor/..." on my drive c.
Inside of the files downloaded from github, there is a file called:
php-binance-api-test.php
Inside this file, there are different lines like:
require 'vendor/autoload.php';
file_put_contents( getenv("HOME") . "/.config/jaggedsoft/php-binance-api.json" ,
I copied the whole vendor directory into my project directory, so he can find his files.
But he is not able to find ".config/jaggedsoft/" because there is no folder named .config.
There is also no file named php-binance-api.json only one called php-binance-api.php
If I try to access some of the sample file, like web_socket_chart.php in examples, he gives me an fatal error:
Fatal error: Uncaught Error: Class 'React\EventLoop\Factory' not found in
...
this might be a file inside of the php-folder of xampp, but how does he load it before to get the class nedded?
I think i messed up the installation of composer? or do I have to choose other place for the project inside of xampp?
What is composer even good for? I would be really thankful, if someone may try to get this run an tell me, what I have done wrong.

Install google api php client on Cent OS in php.ini using include_path

I am trying to install and use google-api-php-client in wordpress and my php applications.
I have requested my administrator manager to install it. They have included the following script to php.ini file.
include_path=".;/usr/local/src/google-api-php-client/src"
Now I want to include and use google api in my wordpress application. I created a file called google.php in wordpress root to test this out, In my research I have found now I need to just include this bit of code in php file and everything will be up and running.
require 'Google/Client.php';
require 'vendor/autoload.php';
At the End I get an error like this:
Fatal error: require(): Failed opening required 'Google/Client.php' (include_path='.;/usr/local/src/google-api-php-client/src') in
Could you help me fix this???
You just need to include the autoload.php file. This file takes care of loading the other classes including Google/Client.php. See this link: https://github.com/google/google-api-php-client

Laravel 5 class

I installed laravel 5.1 on my windows 7, after that i tried to open blog/app/Htttp/routes.php.Now there's a error on my browser saying
"Fatal error: Class 'Route' not found in
C:\xampp\htdocs\Laravel_1\blog\app\Http\routes.php on line 14".
How do i remove this error?
Before a class is available in PHP you will need to require/include it. As you have opened up the file directly in the browser, the laravel application is not bootstrapped and none of the dependencies are loaded to be used.
If you open up public/index.php, you will find a line that says
require __DIR__.'/../bootstrap/autoload.php';
// this later calls composer autoload which compiles a file
// that includes all the classes that you have specified in your `composer.json`.
Now that you have opened the file directly, non of the classes are included and hence you get the error.
I am not sure about your intentions for opening that file directly in the browser. I can only suggest you that the error is expected and you should go through the public/index.php for the application to work properly.

Laravel: How to include file from Vendor folder in Laravel

I am trying to include the YouTube Analytics Service of Google but I can not access it through the Vendor folder.
include(app_path.'path/to/analytics/Google_YoutubeAnalyticsService.php')
It is not working, because it defaults to the App folder.
How can I get out of the App folder and into the Vendor folder (where the YouTube Analytics file is at)?
The error is {
include(C:\xampp\htdocs\mysite\app/path/to/analytics/Google_YoutubeAnalyticsService.php):
failed to open stream: No such file or directory
From where do you want to include that file ?
Place a reference to your file in composer.json autoload object:
"autoload": {
"files":["your_file_path"]
}
Run composer dumpautoload, and you'll have your file :)
Actually you have in the helpers function the path so basically the function base_path give the direction to the root of your project so
echo base_path() . '/vendor';
Should be the route to your vendor folder.
You can se all the documentation in
Helper Functions Laravel
Be sure that you are seeing the documentation of the laravel version that you are using (I put the link for the 4.2 version).
This question was asked a long time ago and the answers reflect that. Most the time now all you need to do is import it using the "use" statement if you installed it with composer. Composer will already reference all the important directories.
It should be something like this, but it will vary depending on the project.
use FolderNameUsuallyGitHubUserName\ClassNameorGitHubProjectName\Class;
That could include a base class as well as some exception classes.
use FolderNameUsuallyGitHubUserName\ClassNameorGitHubProjectName\ClassException;
Usually most packages if compliant with modern composer and php standards work in this fashion.

Magento - zend - backend error

I get the following error when i am logged into the backend in magento
Fatal error: Interface 'Zend_Http_Client_Adapter_Interface' not found in /homepages/45/d210005774/htdocs/websitename/lib/Varien/Http/Adapter/Curl.php on line 176
Also i got this error previously in my index management section in magento
Fatal error: Call to undefined method Zend_Locale_Data::disableCache() in
/homepages/45/d210005774/htdocs/websitename/lib/Zend/Locale/Format.php
on line 153
Could anyone help me out with this? I think the problem is to do with zend framework but i am not sure whats causing this
It looks like there's something wrong with your installation. Either you're missing files from Magento's lib folder, you have damaged files in Magento's lib folder, or (longshot) your PHP include path is pointing in a different location.
First thing I'd do is download a fresh install of your version of Magento, unzip it in a separate folder, and then run
diff -r /homepages/45/d210005774/htdocs/websitename/ /path/to/fresh/magento
This will give you a list of differences between the standard core files and your own.
If you want to diagnose specific files, check
lib/Zend/Http/Client/Adapter/Interface.php
for the missing interface
interface Zend_Http_Client_Adapter_Interface
{
...
}
And check
lib/Zend/Locale
for the missing method
public static function disableCache($flag)
{
self::$_cacheDisabled = (boolean) $flag;
}
Finally, check you PHP include path to ensure there isn't an older copy of Magento and/or Zend being included.
Upload Zend folder again.it works for me.

Categories