将此 Zend Gdata 代码从 ZF 迁移到 ZF2 [英] Migrate this Zend Gdata code from ZF to ZF2

查看:24
本文介绍了将此 Zend Gdata 代码从 ZF 迁移到 ZF2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉问这么糟糕的问题,但我花了 2 个小时没有成功.Zend Docs 太可怕了......

我发现了这个 Zend_Gdata 库和Picasa 数据 API -- loader.php 文件丢失,但它在第 2 行崩溃 Class 'Application\Controller\Zend\Loader\StandardAutoloader' not found,这显然不是正确的路径.

我不知道为什么 ZF 不使用...\vendor\ZF2\library\Zend\Loader\

我正在使用正在运行的 https://github.com/zendframework/ZendSkeletonApplication,但没有任何效果else 与 zf2 一起开箱即用,并且所有帮助主题的描述都不完整.我的眼睛一团糟......

但是这里是代码.

//为您的域更改此项$domain = 'yourdomain.com';$email = 'ad...@yourdomain.com';$passwd = 'p@ssword';$user = 'jsmith';$newuserpassword = 'secretp@assword';//以管理员身份连接到 Google Appsrequire_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');尝试 {$client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, Zend_Gdata_Gapps::AUTH_SERVICE_NAME);} catch (Zend_Gdata_App_CaptchaRequiredException $cre) {echo '验证码图片的网址:'.$cre->getCaptchaUrl() ."\n";echo '令牌 ID:' .$cre->getCaptchaToken() ."\n";} catch (Zend_Gdata_App_AuthException $ae) {echo '问题身份验证:'.$ae->exception() ."\n";}$gdata = new Zend_Gdata_Gapps($client, $domain);//现在修改用户密码$updateUser = $gdata->retrieveUser($user);$updateUser->login->password = $newuserpassword;$updateUser = $updateUser->save();

解决方案

zf2 中没有 Zend_Loader 这样的东西,您发布的代码是针对 zf1 的.如果您的准系统应用程序可以正常工作,那么您的自动加载器就已经可以正常工作了(我假设您使用的是 MVC,并且此代码将放在控制器中,而不是单个文件中).

如果您正确设置了自动加载器,您也不需要使用 Zend_Loader::loadClass.. 因为它们会被自动加载.

至于 zf2 中的 Gdata - 您需要获取包,可以在此处找到 https://packages.zendframework.com/.很好的说明在这里:Zend Framework 2.0.2 YouTube API>

将代码从 zf1 转换为 zf2 应该很容易.

但是很遗憾gdata包已经不再维护,所以建议你使用https://code.google.com/p/google-api-php-client/

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();

解决方案

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/

这篇关于将此 Zend Gdata 代码从 ZF 迁移到 ZF2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆