Google API Loader

HI,

I try to load with the Loader, the src of the Google API. But, it keeps telling me the he can't find the class Google_Client.

Fatal error: Class 'GoogleFileCache' not found in /usr/local/zend/apache2/htdocs/vendor/google/src/GoogleClient.php on line 94

This is my config file (By the way it works very find for the incubator :

'application' => array(

    'controllersDir' => __DIR__ . '/../../app/controllers/',
    'modelsDir'      => __DIR__ . '/../../app/models/',
    'viewsDir'       => __DIR__ . '/../../app/views/',
    'pluginsDir'     => __DIR__ . '/../../app/plugins/',
    'libraryDir'     => __DIR__ . '/../../app/library/',
    'incubator'        =>  __DIR__ . '/../../vendor/phalcon/incubator/Library/',
    'googleAPI'        =>  __DIR__ . '/../../vendor/google/src/'
),

This my code in the index.php :

$config = include(__DIR__ . "/../app/config/config.php");

$loader = new \Phalcon\Loader();

/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerDirs( 

    array(

        $config->application->incubator,
        $config->application->controllersDir,
        $config->application->modelsDir,
        $config->application->pluginsDir,
        $config->application->googleAPI,
))->register();

This the code where I try using it :

public function googleAction() {

    $client = new Google_Client();
    $client->setApplicationName("");

    $client->setClientId('');
    $client->setClientSecret('');
    $client->setRedirectUri('');
    //$client->setDeveloperKey('');

    $oauth2 = new Google_Oauth2Service($client);

    $code = $this->request->get('code');

    if (isset($code)) {

        $client->authenticate($code);
        $_SESSION['token'] = $client->getAccessToken();
        $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
        header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
        return;
    }

    if (isset($_SESSION['token'])) {

        $client->setAccessToken($_SESSION['token']);
    }

    /*if (isset($_REQUEST['logout'])) {

        unset($_SESSION['token']);
        $client->revokeToken();
    }*/

    if ($client->getAccessToken()) {

        $user = $oauth2->userinfo->get();

        // These fields are currently filtered through the PHP sanitize filters.
        // See http://www.php.net/manual/en/filter.filters.sanitize.php
        $email = filter_var($user['email'], FILTER_SANITIZE_EMAIL);
        $img = filter_var($user['picture'], FILTER_VALIDATE_URL);
        $personMarkup = "$email<div><img src='$img?sz=50'></div>";

        // The access token may have been updated lazily.
        $_SESSION['token'] = $client->getAccessToken();
    } else {

        $authUrl = $client->createAuthUrl();
    }

    $this->response->redirect($authUrl, true);
}

Does someone have an idea or a solution ?

Thank you !



81.8k

Is Google_Client.php located at /../../vendor/google/src/?

Try adding an events manager to the loader to check why the route is not being loaded: http://docs.phalconphp.com/en/latest/reference/loader.html#autoloading-events



16.8k

Hi,

Thanks for the answer. Yes, the Google_Client is in the /../../vendor/google/src/

Here's the eventManager answer:

/usr/local/zend/apache2/htdocs/maestro/app/config/../../vendor/phalcon/incubator/Library/Security.php /usr/local/zend/apache2/htdocs/maestro/app/config/../../app/controllers/Security.php /usr/local/zend/apache2/htdocs/maestro/app/config/../../app/models/Security.php /usr/local/zend/apache2/htdocs/maestro/app/config/../../app/plugins/Security.php

it's loon like the folder is not loaded. I don't know why.

Thanks !



81.8k

can you print_r($loader)? This to see the directories in the internal properties.



16.8k

Here's the output of print_r command :

Phalcon\Loader Object ( [eventsManager:protected] => Phalcon\Events\Manager Object ( [events:protected] => Array ( [loader] => Array ( [0] => Closure Object ( [parameter] => Array ( [$event] => [$loader] => ) ) ) ) [collect:protected] => [enablePriorities:protected] => [responses:protected] => ) [foundPath:protected] => [checkedPath:protected] => [prefixes:protected] => [classes:protected] => [extensions:protected] => Array ( [0] => php ) [namespaces:protected] => [directories:protected] => Array ( [0] => /usr/local/zend/apache2/htdocs/maestro/app/config/../../vendor/phalcon/incubator/Library/ [1] => /usr/local/zend/apache2/htdocs/maestro/app/config/../../app/controllers/ [2] => /usr/local/zend/apache2/htdocs/maestro/app/config/../../app/models/ [3] => /usr/local/zend/apache2/htdocs/maestro/app/config/../../app/plugins/ [4] => /usr/local/zend/apache2/htdocs/maestro/app/config/../../vendor/google/src/ ) [_registered:protected] => 1 )



22.0k

Hi , if anyone cant resolve that problem . i did like that;

First change Google_client.php to GoogleClient.php (and of course in file change class name to GoogleClient)

and on config file set the location and registerDirs

DIR . $config->application->googleAPI,

it will be solved



16.8k

Wow I will give it a try.

Thank you.



85
edited Jul '14

Hello,

I got almost same problem for lastest Google API:

Warning: require_once(Google/Auth/AssertionCredentials.php): failed to open stream: No such file or directory in /var/www/phalcon/test/vendor/google/src/Google/Client.php on line 18

Anyone know this issue?

edited Oct '14

Hello,

I got almost same problem for lastest Google API:

``` Warning: require_once(Google/Auth/AssertionCredentials.php): failed to open stream: No such file or directory in /var/www/phalcon/test/vendor/google/src/Google/Client.php on line 18 ``` Anyone know this issue?


मैंने गूगल की संस्थापना निर्देशिका के प्रयोग से inlcude_path को public पद्धति ग्रंथ के index.php में निर्धारित किया। set_include_path(get_include_path() . PATH_SEPARATOR . "path/to/google-api-php-client/src");


I used Google Installation Guide to put include_path in index.php of the public folder. set_include_path(get_include_path() . PATH_SEPARATOR . "path/to/google-api-php-client/src");



85

Thanks for you reply,

I resolved it by this:

My project folders tree:

  • config
  • controllers
  • library
    • Social
      • Google
        • Auth
        • Cache
        • ...
      • Google.php

Set library folder for Phalcon\Loader()

Google.php

<?php

$path = DIR;

setincludepath($path . PATHSEPARATOR . getinclude_path());

class Google extends \Phalcon\Mvc\User\Component {

public function authenticate() {

}

}

Use it:

  • $google = New Google();
  • $google->authenticate();

Sorry, it's very hard to format the thing here.