Php Google API与Zend gdata的身份验证错误

Php Google API与Zend gdata的身份验证错误,php,zend-framework,google-contacts-api,Php,Zend Framework,Google Contacts Api,我正在使用gdata,使用Contact API将联系人添加到我的gmail帐户。当我以localhost的身份在我的开发箱上运行代码时,一切正常。但是,当我将代码移动到生产服务器(www.somedomain.com)时,我得到了“错误:与Google的身份验证失败。原因:BadAuthentication” 这是我的密码: <?php // load Zend Gdata libraries require_once 'Zend/Loader.php'; Zend_Loader::lo

我正在使用gdata,使用Contact API将联系人添加到我的gmail帐户。当我以localhost的身份在我的开发箱上运行代码时,一切正常。但是,当我将代码移动到生产服务器(www.somedomain.com)时,我得到了“错误:与Google的身份验证失败。原因:BadAuthentication”

这是我的密码:

<?php
// load Zend Gdata libraries
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_Feed');

// set credentials for ClientLogin authentication
$user = "something@gmail.com";
$pass = "somepassword";

try {
  // perform login and set protocol version to 3.0
  $client = Zend_Gdata_ClientLogin::getHttpClient(
    $user, $pass, 'cp');
  $gdata = new Zend_Gdata($client);
  $gdata->setMajorProtocolVersion(3);

  // create new entry
  $doc  = new DOMDocument();
  $doc->formatOutput = true;
  $entry = $doc->createElement('atom:entry');
  $entry->setAttributeNS('http://www.w3.org/2000/xmlns/' ,
   'xmlns:atom', 'http://www.w3.org/2005/Atom');
  $entry->setAttributeNS('http://www.w3.org/2000/xmlns/' ,
   'xmlns:gd', 'http://schemas.google.com/g/2005');
   $entry->setAttribute('xmlns', 'http://www.w3.org/2005/Atom');
$entry->setAttribute('xmlns:gd', 'http://schemas.google.com/g/2005');
$entry->setAttribute('xmlns:gContact', 'http://schemas.google.com/contact/2008');
  $doc->appendChild($entry);

  // add name element
  $name = $doc->createElement('gd:name');
  $entry->appendChild($name);
  $fullName = $doc->createElement('gd:fullName', 'Jack Frost');
  $name->appendChild($fullName);

  // add email element
  $email = $doc->createElement('gd:email');
  $email->setAttribute('address' ,'jack.frost@example.com');
  $email->setAttribute('rel' ,'http://schemas.google.com/g/2005#home');
  $entry->appendChild($email);

  // add org name element
  $org = $doc->createElement('gd:organization');
  $org->setAttribute('rel' ,'http://schemas.google.com/g/2005#work');
  $entry->appendChild($org);
  $orgName = $doc->createElement('gd:orgName', 'Winter Inc.');
  $org->appendChild($orgName);

  //add to Friends list
  $group = $doc->createElement('gContact:groupMembershipInfo');
        $group->setAttribute('deleted' ,'false');
        $group->setAttribute('href' ,'http://www.google.com/m8/feeds/groups/' .urlencode($user) . '/base/[groupid]'); 


 //addd to my contacts       
$entry->appendChild($group);

 $group = $doc->createElement('gContact:groupMembershipInfo');
 $group->setAttribute('deleted' ,'false');
 $group->setAttribute('href' ,'http://www.google.com/m8/feeds/groups/' .urlencode($user) . '/base/6');  //adds to Friends

$entry->appendChild($group);

  // insert entry
  $entryResult = $gdata->insertEntry($doc->saveXML(), 
   'http://www.google.com/m8/feeds/contacts/default/full');
  echo '<h2>Add Contact</h2>';
  echo 'The ID of the new entry is: ' . $entryResult->id;
  echo 'The link is: <a href="'.$entryResult->getLink('edit').">".$entryResult->getLink('edit')."</a>";
} catch (Exception $e) {
  die('ERROR:' . $e->getMessage());
}
?>
我进入了gmail安全系统(通过提供的链接),并能够授权该应用程序。问题解决了。现在效果很好


我仍然想要一些关于如何在Zend中使用我的客户端ID、服务帐户和私钥的建议(如果可能的话)。我已经使用Google API php库进行了连接,但我不知道如何在Zend框架中使用它。

在我这方面,我通过输入完整的电子邮件地址作为用户名解决了这个问题(username@gmail.com)


以前,我尝试只使用用户名访问我的帐户…

今天我使用Zend登录YouTube时也发生了同样的事情。感谢您发布解决方案!谷歌将我的活动标记为我自己的活动,但仍然用“BadAuthentication”消息拒绝我的应用程序访问。人力资源管理。
Hi Info, 

Someone recently used your password to try to sign in to your Google Account [someone]@gmail.com. This person was using an application such as an email client or mobile device. 

We prevented the sign-in attempt in case this was a hijacker trying to access your account. Please review the details of the sign-in attempt: 

Saturday, November 2, 2013 9:43:52 PM UTC 
IP Address: [xxx.xxx.xx.xxx] ([xxx.xxx.xx.xxx].unifiedlayer.com.) 
Location: Unknown


If you do not recognize this sign-in attempt, someone else might be trying to access your account. You should sign in to your account and reset your password immediately. 

Reset password  

If this was you, and you are having trouble accessing your account, complete the troubleshooting steps listed at http://support.google.com/mail?p=client_login 

Sincerely,
The Google Accounts team