问题
Version 0.6.3 of the Google API php Client appears to support the importRows command:
public function importRows($tableId, $optParams = array()) {
$params = array('tableId' => $tableId);
$params = array_merge($params, $optParams);
$data = $this->__call('importRows', array($params));
if ($this->useObjects()) {
return new Google_Import($data);
} else {
return $data;
}
}
The importRows documentation doesn't really coincide with the way the function has been implemented in the php Client, as there doesn't appear to be anywhere to pass the CSV information too.
Does anyone have any example code using the Google API php Client 0.6.3 successfully implementing importRows?
I have my implementation working with a service account entering one row at a time. Obviously I'd prefer to do it in bulk rather than loop through an 'insert' or 'sql'.
回答1:
I know this is a late reply, but for future reference, I will reply it anyway: You need to use the uploadType, mimeType and data on the optParams array.
Example:
importRows( [tableId], array(
'uploadType' => 'media' ,
'mimeType' => 'application/octet-stream' ,
'data'=>'1,Moth, 30, 2012')
);
来源:https://stackoverflow.com/questions/17740987/google-php-api-client-fusion-tables-how-to-use-importrows