Grasp_IT
Grasp_IT

Reputation: 13

Error: Zend Framework does not recognize google api auth class objects

namespace Application\Controller;


use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class IndexController extends AbstractActionController
    {
    public function indexAction()
    {
        return new ViewModel();
    }

    public function foo()
    {   

        session_start();
        include_once "/Applications/MAMP/google-api-php-client/examples/templates/base.php";
        set_include_path("/Applications/MAMP/google-api-php-client/src/" . PATH_SEPARATOR . get_include_path());
        require_once "Google/Auth/OAuth2.php";
        require_once    'Google/Client.php';
        require_once 'Google/Auth/AppIdentity.php';
        require_once 'Google/Service/Storage.php';


        $client = new Google_Client();
        $client->setApplicationName('Gmailbox Downlaod');
        $client->setScopes(array('https://www.googleapis.com/auth/plus.me'));
        $client->setClientId('?????');
        $client->setClientSecret('????? (to be inputted)');
        $client->setRedirectUri('https://www.example.com/oauth2callback');
        $client->setApprovalPrompt('force');
        $client->setAccessType('offline');
        $client->setDeveloperKey('MyDeveloperKey');

        header('Location: '.$client->createAuthUrl());
    }

    public function bar()
    {
    }

}

// For some reason this error is returned upon opening the view to the corresponding foo() controller: Fatal error: Class 'Application\Controller\Google_Client' not found in /Applications/MAMP/skeleton-application/module/Application/src/Application/Controller/IndexController.php on line 40

Upvotes: 1

Views: 397

Answers (1)

Tim Fountain
Tim Fountain

Reputation: 33148

You've declared the namespace of Application\Controller, so when you call new Google_Client(); PHP thinks you mean new Application\Controller\Google_Client(). To change this you either need to use the global namespace: new \Google_Client(); or add use Google_Client; after the other calls at the top.

Upvotes: 1

Related Questions