2012-09-10 69 views
0

我在慢慢想出如何使用v1 api的部分代碼,到目前爲止,我可以使用服務帳戶,列表和創建表以及操作表權限來成功進行身份驗證。我目前正在嘗試以編程方式對錶進行樣式設置,並且從服務器收到400個不良請求。我真的不清楚如何生成有效的樣式請求,文檔根本不明確。我的表只包含折線,我希望顏色和重量來自兩個特定列。如何使用Google Fusion Tables php api設置表的樣式?

這是我的代碼:

$resp = $fusionTables->style->insert($id, new Google_StyleSetting(array(
    "polylineOptions"=> new Google_LineStyle(array(
    "strokeColorStyler" => new Google_StyleFunction(array(
     "kind" => "fromColumn", 
     "columnName" => "color" 
)), 
    "strokeWeightStyler"=> new Google_StyleFunction(array(
    "kind" => "fromColumn", 
    "columnName" => "width" 
    )) 
)), 
    "isDefaultForTable" => false 
)) 
); 

using the API documentation,它似乎是合理的,我只需要提供的PolylineOptions與兩個造型器。這與reference api documentation有點不一致,這似乎表明有6個必需的參數來指定所有可能的樣式器的列名,這似乎是錯誤的。無論如何,我確實嘗試過使用參考文檔指出的配置點,線和多邊形的版本,並且無處可查。我也嘗試提供其他可選值,包括樣式名稱和tableId。

任何指針將不勝感激。

回答

1

原來我比我想象的更接近。仔細重新閱讀文檔,似乎樣式工具的「kind」屬性必須爲fusiontables#fromColumn而不是fromColumn

0

最新的PHP客戶端庫v2.0已將類重命名。所以,現在的代碼變成:

$client = new Google_Client(); 
$client->setAuthConfig('oauth-credentials.json'); 
$client->addScope("https://www.googleapis.com/auth/fusiontables"); 

if (isset($_SESSION['access_token']) && $_SESSION['access_token']) 
{ 
    $client->setAccessToken($_SESSION['access_token']); 
    $service = new Google_Service_Fusiontables($client); 
} 

$tableId = "{enter_your_table_id}"; 

$style = $service->style->insert($tableId, new Google_Service_Fusiontables_StyleSetting(array(
     'markerOptions' => new Google_Service_Fusiontables_PointStyle(array(
      "iconStyler" => new Google_Service_Fusiontables_StyleFunction(array(
       "kind" => "fusiontables#fromColumn", 
       "columnName" => "markerColor" 
      )) 
     )), 
     'polylineOptions' => new Google_Service_Fusiontables_LineStyle(array(
      "strokeColorStyler" => new Google_Service_Fusiontables_StyleFunction(array(
       "kind" => "fusiontables#fromColumn", 
       "columnName" => "polylineStrokeColor" 
      )), 
      "strokeWeightStyler"=> new Google_Service_Fusiontables_StyleFunction(array(
       "kind" => "fusiontables#fromColumn", 
       "columnName" => "polylineStrokeWeight" 
      )) 
     )), 
     'polygonOptions' => new Google_Service_Fusiontables_PolygonStyle(array(
      "fillColorStyler" => new Google_Service_Fusiontables_StyleFunction(array(
       "kind" => "fusiontables#fromColumn", 
       "columnName" => "polygonFillColor" 
      )), 
      "strokeColorStyler" => new Google_Service_Fusiontables_StyleFunction(array(
       "kind" => "fusiontables#fromColumn", 
       "columnName" => "polylineStrokeColor" 
      )), 
      "strokeWeightStyler"=> new Google_Service_Fusiontables_StyleFunction(array(
       "kind" => "fusiontables#fromColumn", 
       "columnName" => "polylineStrokeWeight" 
      )) 
     )), 
     "isDefaultForTable" => true 
     )) 
    ); 

更多信息可以在這裏找到:
(1)Creating a style
(2)Reference

相關問題