2017-07-29 109 views
0

我想要寫數據到我的表:寫表與谷歌API表

$spreadsheetId = 'xxx'; 
$range = 'Test!A1:D5'; 

$values = [ 
    'range' => "A1", 
    'majorDimension' => 'DIMENSION_UNSPECIFIED', 
    'values' => [ 
    ["Item", "Cost", "Stocked", "Ship Date"], 
    ["Wheel", "$20.50", "4", "3/1/2016"], 
    ["Door", "$15", "2", "3/15/2016"], 
    ["Engine", "$100", "1", "30/20/2016"], 
    ], 
]; 

$body = new Google_Service_Sheets_ValueRange(array(
    'values' => $values 
)); 
$params = array(
    'valueInputOption' => 'RAW' 
); 
$result = $service->spreadsheets_values->update($spreadsheetId, $range, $body, $params); 

但在日誌中我看到:

PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ 
    "error": { 
    "code": 400, 
    "message": "Invalid JSON payload received. Unknown name \"range\" at 'data.values': Cannot find field.\nInvalid JSON payload received. Unknown name \"major_dimension\" at 'data.values': Cannot find field.", 
    "errors": [ 
     { 
     "message": "Invalid JSON payload received. Unknown name \"range\" at 'data.values': Cannot find field.\nInvalid JSON payload received. Unknown name \"major_dimension\" at 'data.values': Cannot find field.", 
     "domain": "global", 
     "reason": "badRequest" 
     } 
    ], 
    "status": "INVALID_ARGUMENT" 
    } 
} 

我在做什麼錯?我會爲你的作品:)

在實例中,示例代碼感激沒有足夠的信息(https://developers.google.com/sheets/api/guides/values#writing_to_a_single_range

+0

您是否解決了這個問題? – noogui

+0

僅適用於[寫入多個範圍](https://developers.google.com/sheets/api/guides/values#writing_multiple_ranges)。感謝您的支持! – n130

回答

0

你幾乎沒有。不要忘記包含紙張名稱

"range": "Sheet1!A1:D5" 

檢查Basic Writing guide瞭解更多樣本。

+0

結果相同:-( – n130

+0

更新您的代碼 – noogui

+0

在pastebin上:https://pastebin.com/EacpqeYv – n130