2

There seems to be some gaps in the instructions, a little help?

Step 1: Easily access Google APIs from PHP, sounds easy!

Step 2: Install the library, you can install the library by adding it as a dependency to your "composer.json". Never heard of composer, never used json. All I need to do is add "require": {"google/apiclient": "1.0.*@beta"} to my composer.json

Step 3: Composer requires Linux, but isn't the whole point of using App Engine so I don't have to deal with Linux? Ok, setup Debian on Compute Engine and added the following, "sudo curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer" per the instructions.

Step 4: Composer Basic usage... all the Google web page says to do is add the following to Composer, "require": {"google/apiclient": "1.0.*@beta"} so that's of no help. The instructions on the page say the following,

To start using Composer in your project, all you need is a composer.json file. This file describes the dependencies of your project and may contain other metadata as well.

They conveniently forget to explain where/what is the composer.json file? Is this just something people automatically know?

I just want to start using the gogole-api-php-client, but the autoload.php file is gone from their website, and when I try to do it manually it keeps saying I am missing GuzzleHttp/Collection. So I thought I would try to put it together in Composer because it's so "easy". Does anyone know of a simple set of steps/instructions to plow through this without spending the next 10 hours learning json, composer, and linux? Does anyone actually have this thing working, because I'm starting to think it doesn't even work. Both of these websites need to take ease off on their overuse of the words "easy" and "simple" because I don't think they understand the meaning of those words. "Excessively complicated" and "extremely vague" would suit them better.

Mike
  • 247
  • 2
  • 5
  • 10

2 Answers2

3

Sorry for the confusion, we've updated the docs to make this more clear.

We recommend using composer because it is the standard package manager for PHP these days. The other comment here details that process really well.

Another way is to go to Releases, and any package marked google-api-php-client-[RELEASE_NAME].zip will include all the dependencies. Download and extract this file, include the autoloader (at vendor/autoload.php), and you'll be all set!

Let me know if you run into any problems.

Community
  • 1
  • 1
Brent Shaffer
  • 491
  • 3
  • 11
  • You might want to poke the YouTube API guys they haven't updated their examples for this. – Linda Lawton - DaImTo Nov 04 '15 at 08:16
  • Good luck with that. For me including it still return that it could not include the Youtube classes. – Gary Carlyle Cook Apr 21 '17 at 21:15
  • Nothing I try can get the PHP version to work. It always has a Youtube class issue like it can't find it. Also why even have the composer version if the PHP version is just that easy? It is like they know the PHP version doesn't work but rather than fix it or remove it they release it with the Composer version. – Gary Carlyle Cook Apr 22 '17 at 10:53
2

The documentation had been pointing to the wrong (unstable aka master) branch it seems. You should be able to just install the v1-master branch and get it running. The HelloAnalytics example should work with the v1-master for example.

git clone -b v1-master https://github.com/google/google-api-php-client.git

To answer your the question in the title more directly, if you for example want to run the unstable branch - Install composer (composer.phar) to your project folder and just run the command:

php composer.phar require "google/apiclient:~2.0@dev"

This should result in a folder called vendor which will contain autoload.php. Just include this row in your code and you should be able to get it running.

require_once 'vendor/autoload.php';

I'm quite new to this so someone else might be able to explain this better.

stugots
  • 44
  • 3
  • The documentation has been updated to include the `v1-master` argument, so they all point to the stable branches. As for the rest of this, your advice is spot on! – Brent Shaffer Nov 03 '15 at 22:27
  • After require_once '/google-api-php-client/src/Google/autoload.php'); from v1-master and having only `$KEY_FILE_LOCATION = __DIR__ . '/prod-b5386f72b23d.json'; $client = new Google_Client();` does not working or printing $client throws Error 500. Also used almost all the release from google api either it will throw '[' error or failed to load guzzlehttp. Help me in getting the correct google client which will work with HelloAnalytics example. – Viswa Apr 11 '17 at 12:22
  • there is NO SUCH FOLDER called VENDOR. -1. Check your answer or provide a complete answer. – ekashking Feb 14 '21 at 06:06