Mike
Mike

Reputation: 257

Google API PHP Client autoload.php is required but missing?

Step 1: Download google-api-php-client

Step 2: Change directory name to "api" and upload to Google App Engine

Step 3: Follow instructions and keep adding the following lines to because of specific errors saying files missing

set_include_path( get_include_path() . PATH_SEPARATOR . 'api/src' );
require_once 'Google/Collection.php';
require_once 'Google/Model.php';
require_once 'Google/Exception.php';
require_once 'Google/Task/Exception.php';
require_once 'Google/Service.php';
require_once 'Google/Service/Resource.php';
require_once 'Google/Service/Gmail.php';

Step 4: Receive the following error (used {...} for removed items),

Warning: require_once(/base/data/home/apps/{...}/api/src/Google/autoload.php): 
failed to open stream: No such file or directory in 
/base/data/home/apps/{...}/api/src/Google/Collection.php on line 4 Fatal
error: require_once(): Failed opening required '/base/data/home/apps/{...}/api/src/Google/autoload.php'
(include_path='.;/base/data/home/{...}/;/base/data/home/runtimes/php/sdk;api/src')
in /base/data/home/apps/{...}/api/src/Google/Collection.php on line 4

The file "Collection.php" is required by other files, but it requires "autoload.php" file. There is no "autoload.php" file. I have searched for hours and am completely lost. Why would their be a dependency of a file that doesn't exist and if it needs to be created somehow, why bury the instructions?

All I want to do is use this to check for unread emails, does the API not work? Is there another way to check a users unread emails baked into GAE?

Upvotes: 2

Views: 12929

Answers (4)

Prafulla Kumar Sahu
Prafulla Kumar Sahu

Reputation: 9703

The file you need is here

<?php /* * Copyright 2014 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function google_api_php_client_autoload($className) { $classPath = explode('_', $className); if ($classPath[0] != 'Google') { return; } // Drop 'Google', and maximum class file path depth in this project is 3. $classPath = array_slice($classPath, 1, 2); $filePath = dirname(__FILE__) . '/' . implode('/', $classPath) . '.php'; if (file_exists($filePath)) { require_once($filePath); } } spl_autoload_register('google_api_php_client_autoload');

Please try using it and let me know if It worked for you.

Upvotes: 2

user5505767
user5505767

Reputation: 11

Last week, GitHub had the autoload.php file and this week it does not. I'm not too keen on using composer - call me old school

Here's the content of the autoload.php file that I had last week that might help you maybe?

<?php
/*
 * Copyright 2014 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// PHP 5.2 compatibility: E_USER_DEPRECATED was added in 5.3
if (!defined('E_USER_DEPRECATED')) {
  define('E_USER_DEPRECATED', E_USER_WARNING);
}

$error = "google-api-php-client's autoloader was moved to src/Google/autoload.php in 1.1.3. This ";
$error .= "redirect will be removed in 1.2. Please adjust your code to use the new location.";
trigger_error($error, E_USER_DEPRECATED);
require_once dirname(__FILE__) . '/src/Google/autoload.php';

Upvotes: 0

Josh J
Josh J

Reputation: 6893

The source shows what looks like a bug(?) where if it cannot find Google_Client then it tries to include an autoload.php file.

Add this as your first include

require_once 'Google/Client.php';

edit So yeah, not only that but it also looks like you'll need to run composer like mnv said.

Upvotes: 0

Related Questions