2013-11-03 3 views
2

gData를 사용하여 Contact API를 사용하여 Gmail 계정에 연락처를 추가하고 있습니다. 개발 상자에서 로컬 호스트로 코드를 실행하면 모든 것이 정상적으로 작동합니다. 그러나 프로덕션 서버 (www.somedomain.com)로 코드를 옮길 때 "오류 : Google 인증 실패 이유 : BadAuthentication"이 표시됩니다.Google API Zend gData에 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 = "[email protected]"; 
$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' ,'[email protected]'); 
    $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()); 
} 
?> 

내가 대신 서비스에 대한 OAuth를를 사용해야합니다

여기 내 코드입니까? Zend Gdata를 사용하여이 작업을 수행하는 방법에 대한 설명서를 찾을 수 없었습니다. 나는 아직도 더 나은 인증 방법에 대한 질문이 있지만 문제는이 경우에 무엇인지 파악 -

확인을 : -

편집 답 발견했다. . (제공된 링크를 통해)

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 

내가 Gmail은 보안에 가서 응용 프로그램에 권한을 부여 할 수 있었다 : I Gmail을 선택하면 구글에 로그인 내 응용 프로그램의 의심했다, 나는 다음과 같은 받았다. 문제 해결됨. 완벽하게 작동합니다.

내 클라이언트 ID, 서비스 계정 및 개인 키 (가능한 경우)를 사용하는 방법에 대한 몇 가지 지침이 필요합니다. Google API PHP 라이브러리를 사용하여 연결했지만 Zend 프레임 워크 내에서이를 사용하는 방법을 볼 수 없습니다.

+0

같은 일이 오늘 저와 무슨 일이 있었 ... 사용자 이름 만 내 계정에 접근을 시도했습니다. 솔루션을 게시 주셔서 감사합니다! –

+0

Google은 내 활동이 내 것으로 표시되었지만 여전히 "BadAuthentication"메시지로 내 앱 액세스를 거부합니다. Hrm. – Dutchie432

답변

0

내 의견으로는 전체 이메일 주소를 username ([email protected])으로 입력하여 문제를 해결했습니다.

이전에, 나는 YouTube에 로그인 젠드를 사용하는 동안

관련 문제