2015-10-20 59 views
0

我想將工作表添加到現有的Google電子表格中,但是速度並不快。以下不適合我。下面的POST請求是否錯誤?使用Perl發佈到Google表格LWP

注意:我的工作表確實是公開的,並已在網絡上發佈。由於能夠成功獲取GET請求,因此得到確認。

link to Google documentation

use strict; 
use warnings; 
use feature 'say'; 
use LWP::UserAgent; 

my $agent = LWP::UserAgent->new; 

my $key = "some key"; 
my $url = "https://spreadsheets.google.com/feeds/worksheets/$key/public/full" 
my $xml = join "\n", 
    '<entry xmlns="http://www.w3.org/2005/Atom"', 
      'xmlns:gs="http://schemas.google.com/spreadsheets/2006">', 
     '<title>Expenses</title>', 
     '<gs:rowCount>50</gs:rowCount>', 
     '<gs:colCount>10</gs:colCount>', 
    '</entry>'; 

my $response = $agent->post(
    $url, 
    'Content-Type' => 'application/atom+xml', 
    'Content' => $xml 
); 
$response->is_success && say "OK"; 
$response->is_error && say "error"; 
+1

是真正的代碼,你跑了?該代碼因運行時異常而失敗,因爲未定義「$ agent」。你缺少'我的$ agent = LWP :: UserAgent-> new();'總是使用'use strict;使用警告;'!否則,請張貼您實際使用的代碼以及'$ response-> as_string'的結果。 (不要忘記在密鑰出現在輸出中時對其進行混淆) – ikegami

+0

這是來自代碼體系的摘錄。 「HTTP/1.1 405方法不允許」,然後是一堆東西。嗯,也許郵政不允許在公共紙上? – beasy

+0

你有鏈接到API的文檔? – ikegami

回答