2012-12-24 29 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; 

Vì vậy, thay vì nhận danh sách các trang web từ $ curl-> phản hồi, tôi nhận được thông báo - "Nội dung không được phép trong prolog". Tôi đã nhìn khắp mọi nơi và không thể tìm ra giải pháp, xin hãy giúp đỡ! Cảm ơn! :)API Google Sites qua CURL trong PHP - Nhận "Nội dung không được phép trong prolog".

Đây là XML đó là nghĩa vụ để được trả lại bởi các phản ứng:

<?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> 

tôi không thể dán nguồn gốc của "https://sites.google.com/feeds/site/ clevertechie.mygbiz.com "vì không thể truy cập trực tiếp mà không có mã thông báo ủy quyền, được chỉ định trong tiêu đề. Cách duy nhất để truy xuất dữ liệu của nó là sử dụng mã thông báo trong các tiêu đề mà tôi đã thực hiện. Thay vì nhận được trên XML, tôi nhận được "Nội dung không được phép trong prolog".

var_dump của $ curl:

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) } } 

$ auth chỉ là một chuỗi, nó không phải được định dạng như XML. Tôi đã xác minh rằng không có thêm dấu cách hoặc ký tự nào và nó khớp chính xác với số được trả về bởi yêu cầu $ curl-> đầu tiên.

+0

Bạn có thể kết xuất biến '$ auth' trước khi đặt tiêu đề (hoặc' var_dump' tiêu đề) không? Ngoài ra, bạn có thể dán nguồn * chính xác * của 'https: // sites.google.com/feeds/site/clevertechie.mygbiz.com' không? Có thể có vấn đề với XML (không gian cụ thể trước khi khai báo '') –

+0

Khi đọc nhận xét của riêng tôi, tôi không ngụ ý rằng bạn nên chia sẻ giá trị '$ auth' của bạn ... là một cuộc gọi xấu :) Tuy nhiên, tôi nghi ngờ rằng đó là một vấn đề với mã hóa XML, do đó, hãy đăng phản hồi XML mà tệp * nên * trả về. –

+0

Bạn cũng có thể đăng 'var_dump' của' $ curl' không? Obfuscate bất kỳ dữ liệu bí mật, nhưng cũng đảm bảo rằng độ dài chuỗi là chính xác, vì nó có thể 'cắt()' là thiếu một ký tự khoảng trắng ... ví dụ, nó không bắt ký tự không có chiều rộng không gian ('\ u200B ') –

Trả lời

1

Để loại yêu cầu dưới dạng POST (với nội dung là tải trọng xml nguyên tử), đặt loại nội dung thành "application/atom + xml" nhưng chuyển tất cả các oAuth thành GET, tức là thoát (urlEncoded) giá trị trên chuỗi truy vấn URL.

Các vấn đề liên quan