Google PHP API Client & Fusion Tables: How to use importRows?

那年仲夏 提交于 2019-11-27 07:17:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!