내 Gmail 계정에서 일부 이메일의 내용을 가져오고 싶습니다. 이 작업을 수행하려면 PHP cURL 확장을 사용하고 싶습니다. 내 첫 시도에서 다음 단계를 따라 갔다.PHP cURL 확장자를 사용하여 두 웹 사이트간에 동일한 쿠키를 공유합니다.
- PHP 코드에서 https://www.google.com/accounts/ServiceLoginAuth의 내용을 출력한다.
- 브라우저에서 사용자는 로그인 할 사용자 이름과 암호를 입력합니다.
- PHP 코드에서 cookie.txt라는 파일에 쿠키를 저장하십시오.
- PHP 코드에서 cookie.txt에서 검색 한 쿠키와 함께 https://mail.google.com/에게 요청을 보내고 내용을 출력하십시오.
다음 코드는 작동하지 않습니다
$login_url = 'https://www.google.com/accounts/ServiceLoginAuth';
$gmail_url = 'https://mail.google.com/';
$cookie_file = dirname(__FILE__) . '/cookie.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_URL, $login_url);
$output = curl_exec($ch);
echo $output;
curl_setopt($ch, CURLOPT_URL, $gmail_url);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$output = curl_exec($ch);
echo $output;
curl_close($ch);
왜 작동하지 않습니까? 무슨 일이야? – SLaks
@Slaks : '로그인'버튼을 클릭하면 브라우저가 localhost에서 나가 https://www.google.com/accounts/ServiceLoginAuth로 바로 이동합니다. 따라서 유용한 쿠키가 cookie.txt에 저장되지 않습니다 – powerboy