2012-12-24 2 views
8
$curl = new Curl(); 
$data = 'Email='.urlencode('[email protected]').'&Passwd='.urlencode('MYPASSWORD').'&accountType=GOOGLE&source=Google-cURL-Example&service=jotspot'; 
$curl->post('https://www.google.com/accounts/ClientLogin',$data); 

//match authorization token 
preg_match("!Auth=(.*)!",$curl->response,$match); 
$auth = $match[1]; 

//set curl headers 
$curl->set_headers(array(
'Content-Type: application/atom+xml; charset=utf-8', 
'Host: sites.google.com', 
'GData-Version: 1.4', 
'Authorization: GoogleLogin auth='. trim($auth))); 

//get a list of sites associated with my domain 
$curl->get('https://sites.google.com/feeds/site/clevertechie.mygbiz.com'); 

//contains data returned by $curl->get(); 
echo $curl->response; 

그래서 $ curl-> response에서 사이트 목록을 가져 오는 대신 "내용이 프롤로그에 허용되지 않습니다."라는 메시지가 나타납니다. 나는 어디에서나 보았고 해결책을 찾을 수 없었습니다. 도와주세요! 감사! :)이 응답으로 반환 할 예상되는 XML은PHP의 CURL을 통한 Google 사이트 도구 API - '프롤로그에서 콘텐츠를 사용할 수 없습니다.'

:

<?xml version='1.0' encoding='UTF-8'?> 
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gAcl='http://schemas.google.com/acl/2007' xmlns:sites='http://schemas.google.com/sites/2008' xmlns:gs='http://schemas.google.com/spreadsheets/2006' xmlns:dc='http://purl.org/dc/terms' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'> 
<updated>2012-10-31T19:00:17.297Z</updated> 
<app:edited xmlns:app='http://www.w3.org/2007/app'>2012-10-31T19:00:17.297Z</app:edited> 
<title>My Site Title</title> 
<summary>My Site Summary</summary> 
<sites:siteName>my-site-title</sites:siteName> 
<sites:theme>slate</sites:theme> 
</entry> 

나는 https://sites.google.com/feeds/site/ "의 소스를 붙여 넣을 수 없습니다 clevertechie.mygbiz.com "은 헤더에 지정된 승인 토큰없이 직접 액세스 할 수 없으므로 데이터를 검색하는 유일한 방법은 내가 수행 한 헤더에 토큰을 사용하는 것입니다. XML 대신에 "프롤로그에서 컨텐츠가 허용되지 않습니다"라는 메시지가 나타납니다. $ 컬의

위해서 var_dump :

object(Curl)#1 (11) { ["curl_resource":protected]=> resource(4) of type (Unknown) ["proxy":protected]=> bool(false) 
["proxy_type":protected]=> NULL ["response"]=> string(33) "Content is not allowed in prolog." ["time"]=> float(249) 
["info"]=> array(26) { ["url"]=> string(59) "https://sites.google.com/feeds/site/clevertechie.mygbiz.com" 
["content_type"]=> string(24) "text/html; charset=UTF-8" ["http_code"]=> int(400) ["header_size"]=> int(676) 
["request_size"]=> int(1935) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(20) ["redirect_count"]=> int(0) 
["total_time"]=> float(0.249) ["namelookup_time"]=> float(0.015) ["connect_time"]=> float(0.046) 
["pretransfer_time"]=> float(0.109) ["size_upload"]=> float(111) ["size_download"]=> float(33) 
["speed_download"]=> float(132) ["speed_upload"]=> float(445) ["download_content_length"]=> float(-1) 
["upload_content_length"]=> float(111) ["starttransfer_time"]=> float(0.249) ["redirect_time"]=> float(0) 
["certinfo"]=> array(0) { } ["primary_ip"]=> string(14) "74.125.224.194" ["primary_port"]=> int(443) 
["local_ip"]=> string(13) "192.168.1.133" ["local_port"]=> int(61985) ["redirect_url"]=> string(0) "" } 
["error"]=> NULL ["custom_headers"]=> NULL ["cookie_file"]=> string(46) "cookies.txt" 
["custom_curl_options":protected]=> array(3) { [47]=> int(1) [10015]=> string(111) 
"Email=MYEMAIL&Passwd=MYPASSWORD&accountType=GOOGLE&source=Google-cURL-Example&service=jotspot" 
[10023]=> array(4) { [0]=> string(49) "Content-Type: application/atom+xml; charset=utf-8" 
[1]=> string(22) "Host: sites.google.com" [2]=> string(18) "GData-Version: 1.4" [3]=> string(320) 
"Authorization: GoogleLogin auth=DQAAAMMAAAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" } } ["curl_options":protected]=> array(9) { [10018]=> string(74) 
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1" [10016]=> string(22) 
"http://www.google.com/" [13]=> int(60) [78]=> int(60) [19913]=> int(1) [52]=> int(1) [64]=> int(0) [81]=> int(0) [42]=> int(0) } } 

$의 인증은이 XML로 포맷 가정뿐만 아니라 문자열입니다. 여분의 공백이나 문자가 없으며 첫 번째 $ curl-> post 요청에 의해 반환 된 것과 정확히 일치한다는 것을 확인했습니다.

+0

헤더를 설정하기 전에 (또는'var_dump' 헤더를 사용하여)'$ auth' 변수를 덤프 할 수 있습니까? 또한, https : // sites.google.com/feeds/site/clevertechie.mygbiz.com의 정확한 소스에 붙여 넣을 수 있습니까? XML에 문제가있는 것 같습니다. (구체적으로 ''선언 전에) –

+0

제 자신의 의견을 읽으면서'$ auth' 값을 공유해야한다는 의미는 아닙니다. 나쁜 호출 :) 그러나, 나는 그것이 XML 인코딩에 관한 문제라고 생각한다. 그래서 파일 *이 리턴해야만하는 XML 응답을 게시한다. –

+0

'$ curl'의'var_dump'도 게시 할 수 있습니까? 기밀 데이터를 난독화할뿐만 아니라'trim()'에 공백 문자가 누락되었을 가능성이 있으므로 문자열 길이가 정확한지 확인하십시오. 예를 들어, 공백 문자가없는 경우 ('\ u200B ') –

답변

1

요청 유형을 POST (콘텐츠가 atom xml 페이로드 인 콘텐츠)로두고 콘텐츠 유형을 "application/atom + xml"으로 설정하고 oAuth를 모두 GET, 즉 이스케이프 (urlEncoded) URL 쿼리 문자열의 값