Migrate this Zend Gdata code from ZF to ZF2

匿名 (未验证) 提交于 2019-12-03 09:52:54

问题:

Sorry for such a bad question but I spend 2 hours without any success. Zend Docs are horrible ...

I have found this Zend_Gdata library and Picasa data API -- loader.php file missing, but its crashing at line 2 Class 'Application\Controller\Zend\Loader\StandardAutoloader' not found, which obviously isn't the correct path.

I am not sure why ZF does not use ...\vendor\ZF2\library\Zend\Loader\

Im using https://github.com/zendframework/ZendSkeletonApplication which is working, but nothing else works out of box with zf2 and all help topics are described incompletely. A mess in my eyes ...

However here is the code.

//Change this for your domain $domain = 'yourdomain.com'; $email = 'ad...@yourdomain.com'; $passwd = 'p@ssword'; $user = 'jsmith'; $newuserpassword = 'secretp@assword';  //Connect as admin to Google Apps require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Http_Client'); Zend_Loader::loadClass('Zend_Gdata'); Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); Zend_Loader::loadClass('Zend_Gdata_Gapps'); try {   $client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd,     Zend_Gdata_Gapps::AUTH_SERVICE_NAME); } catch (Zend_Gdata_App_CaptchaRequiredException $cre) {     echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "\n";     echo 'Token ID: ' . $cre->getCaptchaToken() . "\n"; } catch (Zend_Gdata_App_AuthException $ae) {    echo 'Problem authenticating: ' . $ae->exception() . "\n"; } $gdata = new Zend_Gdata_Gapps($client, $domain);  //Now change the user's password $updateUser = $gdata->retrieveUser($user); $updateUser->login->password = $newuserpassword; $updateUser = $updateUser->save();

回答1:

There's no such thing as Zend_Loader in zf2 and the code you have posted is for zf1. If you have the barebones application working, then you will already have the autoloader working correctly (I presume you're using MVC and this code is to go in a controller, not a single file).

If you have the autoloader setup correctly, you also don't need to use Zend_Loader::loadClass.. as they will be autoloaded.

As for Gdata in zf2 - you will need to get the package, which can be found here https://packages.zendframework.com/. Good instructions are here: Zend Framework 2.0.2 YouTube API

Converting the code from zf1 to zf2 should be pretty easy.

However, unfortunately the gdata package is no longer maintained, so you are advised to use https://code.google.com/p/google-api-php-client/



回答2:

There's a new API that you can use even if Zend 1 or 2:

https://github.com/google/google-api-php-client

Here's the page with installation instructions and a getting started:

https://developers.google.com/api-client-library/php/

And here are the available services:

https://github.com/google/google-api-php-client/tree/master/src/Google/Service

Hope it help.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!