使用 Zend Framework 1 Gdata 获取 Google Plus 图片
Get Google Plus Images Using Zend Framework 1 Gdata
我一直在寻找这个问题的答案很长一段时间了。我在这里调查了其他问题,但找不到与我的情况相关的问题。谷歌搜索这个问题也没有帮助。
基本上,我使用 ZF1 的 Gdata class 访问照片 api。几周前它还在工作,但停止工作了(我不确定是否有代码更改或 Google 完全停止了 API)。
我的代码如下:
private function _loadZendLibraries()
{
set_include_path(APP.'vendors');
require_once('Zend/Loader.php');
$Zend_Loader = new Zend_Loader();
$Zend_Loader->loadClass('Zend_Gdata');
$Zend_Loader->loadClass('Zend_Gdata_ClientLogin');
$Zend_Loader->loadClass('Zend_Gdata_AuthSub');
$Zend_Loader->loadClass('Zend_Gdata_Photos');
$Zend_Loader->loadClass('Zend_Gdata_Photos_UserQuery');
$Zend_Loader->loadClass('Zend_Gdata_Photos_AlbumQuery');
$Zend_Loader->loadClass('Zend_Gdata_Photos_PhotoQuery');
$Zend_Loader->loadClass('Zend_Gdata_App_Extension_Category');
}
function checkGoogleImages(){
$this->_loadZendLibraries();
$service_name = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
$user = '********@gmail.com';
$pass = '********';
try {
$this->client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service_name);
} catch (Zend_Gdata_App_Exception $e) {
$this->Session->setFlash("Error: " . $e->getMessage(). "<br /> You need go to Google+ => Settings => Applications and APPROVE the application to connect.", 'flash_failure');
$this->Session->delete('GOOGLE_USER');
$this->redirect($this->referer());
}
print "<pre>";
print_r($this->client);
exit;
}
在一台服务器上它给出:
Notice (8): Undefined offset: 1 [APP/vendors/Zend/Gdata/ClientLogin.php, line 150]
另一方面:
Notice (8): Undefined offset: 1 [APP/vendors/Zend/Gdata/ClientLogin.php, line 150]
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 403 Authorization required' in /home/home/mysite/app/vendors/Zend/Gdata/App.php:717 Stack trace: #0 /home/home/mysite/app/vendors/Zend/Gdata.php(221): Zend_Gdata_App->performHttpRequest('GET', 'https://picasaw...', Array, NULL, NULL, NULL) #1 /home/home/mysite/app/vendors/Zend/Gdata/App.php(883): Zend_Gdata->performHttpRequest('GET', 'https://picasaw...', Array) #2 /home/home/mysite/app/vendors/Zend/Gdata/App.php(771): Zend_Gdata_App->get('https://picasaw...', NULL) #3 /home/home/mysite/app/vendors/Zend/Gdata/App.php(213): Zend_Gdata_App->importUrl('https://picasaw...', 'Zend_Gdata_Phot...', NULL) #4 /home/home/mysite/app/vendors/Zend/Gdata.php(162): Zend_Gdata_App->getFeed('https://picasaw...', 'Zend_Gdata_Phot...') #5 /home/home/mysite/app/vendors/Zend/Gdata/Photos.php(175): Zend_Gdata->getFeed('https://picasaw...', 'Zend_Gdata_Phot...') #6 /home/home/mysite/app/controllers/photos_ in /home/home/mysite/app/vendors/Zend/Gdata/App.php on line 717
注意: 我正在使用 CakePHP 1.3 和 Zend Framework 1.12.7。我只是想从 Google Plus 中检索特定帐户的图像。用户输入他们的电子邮件和密码,应用程序应提取他们的图像。
我似乎找不到这个问题的答案。 google 是否完全阻止了 API?是不是用法有误?
提前致谢。
Zend_Gdata 使用 ClientLogin,它已于 2012 年 4 月 20 日弃用并于 2015 年 5 月 26 日关闭。此代码将不再有效,您需要切换到使用 Oauth2。
您可以使用当前的Google PHP client library to authenticate then use the access token created there to access it. This answer may help
我一直在寻找这个问题的答案很长一段时间了。我在这里调查了其他问题,但找不到与我的情况相关的问题。谷歌搜索这个问题也没有帮助。
基本上,我使用 ZF1 的 Gdata class 访问照片 api。几周前它还在工作,但停止工作了(我不确定是否有代码更改或 Google 完全停止了 API)。
我的代码如下:
private function _loadZendLibraries()
{
set_include_path(APP.'vendors');
require_once('Zend/Loader.php');
$Zend_Loader = new Zend_Loader();
$Zend_Loader->loadClass('Zend_Gdata');
$Zend_Loader->loadClass('Zend_Gdata_ClientLogin');
$Zend_Loader->loadClass('Zend_Gdata_AuthSub');
$Zend_Loader->loadClass('Zend_Gdata_Photos');
$Zend_Loader->loadClass('Zend_Gdata_Photos_UserQuery');
$Zend_Loader->loadClass('Zend_Gdata_Photos_AlbumQuery');
$Zend_Loader->loadClass('Zend_Gdata_Photos_PhotoQuery');
$Zend_Loader->loadClass('Zend_Gdata_App_Extension_Category');
}
function checkGoogleImages(){
$this->_loadZendLibraries();
$service_name = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
$user = '********@gmail.com';
$pass = '********';
try {
$this->client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service_name);
} catch (Zend_Gdata_App_Exception $e) {
$this->Session->setFlash("Error: " . $e->getMessage(). "<br /> You need go to Google+ => Settings => Applications and APPROVE the application to connect.", 'flash_failure');
$this->Session->delete('GOOGLE_USER');
$this->redirect($this->referer());
}
print "<pre>";
print_r($this->client);
exit;
}
在一台服务器上它给出:
Notice (8): Undefined offset: 1 [APP/vendors/Zend/Gdata/ClientLogin.php, line 150]
另一方面:
Notice (8): Undefined offset: 1 [APP/vendors/Zend/Gdata/ClientLogin.php, line 150] Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 403 Authorization required' in /home/home/mysite/app/vendors/Zend/Gdata/App.php:717 Stack trace: #0 /home/home/mysite/app/vendors/Zend/Gdata.php(221): Zend_Gdata_App->performHttpRequest('GET', 'https://picasaw...', Array, NULL, NULL, NULL) #1 /home/home/mysite/app/vendors/Zend/Gdata/App.php(883): Zend_Gdata->performHttpRequest('GET', 'https://picasaw...', Array) #2 /home/home/mysite/app/vendors/Zend/Gdata/App.php(771): Zend_Gdata_App->get('https://picasaw...', NULL) #3 /home/home/mysite/app/vendors/Zend/Gdata/App.php(213): Zend_Gdata_App->importUrl('https://picasaw...', 'Zend_Gdata_Phot...', NULL) #4 /home/home/mysite/app/vendors/Zend/Gdata.php(162): Zend_Gdata_App->getFeed('https://picasaw...', 'Zend_Gdata_Phot...') #5 /home/home/mysite/app/vendors/Zend/Gdata/Photos.php(175): Zend_Gdata->getFeed('https://picasaw...', 'Zend_Gdata_Phot...') #6 /home/home/mysite/app/controllers/photos_ in /home/home/mysite/app/vendors/Zend/Gdata/App.php on line 717
注意: 我正在使用 CakePHP 1.3 和 Zend Framework 1.12.7。我只是想从 Google Plus 中检索特定帐户的图像。用户输入他们的电子邮件和密码,应用程序应提取他们的图像。
我似乎找不到这个问题的答案。 google 是否完全阻止了 API?是不是用法有误?
提前致谢。
Zend_Gdata 使用 ClientLogin,它已于 2012 年 4 月 20 日弃用并于 2015 年 5 月 26 日关闭。此代码将不再有效,您需要切换到使用 Oauth2。
您可以使用当前的Google PHP client library to authenticate then use the access token created there to access it. This answer may help