要求
HTTP 要求
GET https://www.googleapis.com/calendar/v3/colors
授權
這項要求至少允許擁有下列其中一個範圍的授權:
範圍 |
---|
https://www.googleapis.com/auth/calendar |
https://www.googleapis.com/auth/calendar.readonly |
詳情請參閱「驗證與授權」網頁。
要求主體
請勿使用這個方法提供請求主體。
回應
如果成功的話,這個方法會在回應主體中傳回色彩資源。
範例
注意:這個方法適用的程式語言眾多,我們只在此提供部分程式碼範例,完整的支援語言清單請參閱用戶端程式庫頁面。
Java
使用 Java 用戶端程式庫。
import com.google.api.services.calendar.Calendar; import com.google.api.services.calendar.model.Colors; import com.google.api.services.calendar.model.ColorDefinition; import java.util.Map; // ... // Initialize Calendar service with valid OAuth credentials Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials) .setApplicationName("applicationName").build(); // Retrieve color definitions for calendars and events Colors colors = service.colors().get().execute(); // Print available calendar list entry colors for (Map.Entry<String, ColorDefinition> color : colors.getCalendar().entrySet()) { System.out.println("ColorId : " + color.getKey()); System.out.println(" Background: " + color.getValue().getBackground()); System.out.println(" Foreground: " + color.getValue().getForeground()); } // Print available event colors for (Map.Entry<String, ColorDefinition> color : colors.getEvent().entrySet()) { System.out.println("ColorId : " + color.getKey()); System.out.println(" Background: " + color.getValue().getBackground()); System.out.println(" Foreground: " + color.getValue().getForeground()); }
Python
使用 Python 用戶端程式庫。
colors = service.colors().get().execute() # Print available calendarListEntry colors. for id, color in colors['calendar'].iteritem(): print 'colorId: %s' % id print ' Background: %s' % color['background'] print ' Foreground: %s' % color['foreground'] # Print available event colors. for id, color in colors['event'].iteritem(): print 'colorId: %s' % id print ' Background: %s' % color['background'] print ' Foreground: %s' % color['foreground']
PHP
使用 PHP 用戶端程式庫。
$colors = $service->colors->get(); // Print available calendarListEntry colors. foreach ($colors->getCalendar() as $key => $color) { print "colorId : {$key}\n"; print " Background: {$color->getBackground()}\n"; print " Foreground: {$color->getForeground()}\n"; } // Print available event colors. foreach ($colors->getEvent() as $key => $color) { print "colorId : {$key}\n"; print " Background: {$color->getBackground()}\n"; print " Foreground: {$color->getForeground()}\n"; }
小茹
使用 Ruby 用戶端程式庫。
result = client.get_color() # Print available calendarListEntry colors. result.calendar.keys.each do |key| print "colorId: #{key}\n" print " Background: #{result.calendar[key].background}\n" print " Foreground: #{result.calendar[key].foreground}\n" end # Print available event colors. result.event.keys.each do |key| print "colorId: #{key}\n" print " Background: #{result.event[key].background}\n" print " Foreground: #{result.event[key].foreground}\n" end
.NET
使用 .NET 用戶端程式庫。
Colors colors = service.Colors.Get().Fetch(); // Print available calendarListEntry colors. foreach (KeyValuePair<String, ColorDefinition> color in colors.Calendar) { System.out.println("ColorId : " + color.Key); System.out.println(" Background: " + color.Value.Background); System.out.println(" Foreground: " + color.Value.Foreground); } // Print available event colors. foreach (KeyValuePair<String, ColorDefinition> color in colors.Event) { System.out.println("ColorId : " + color.Key); System.out.println(" Background: " + color.Value.Background); System.out.println(" Foreground: " + color.Value.Foreground); }
試試看!
使用下方的 APIs Explorer,針對即時資料呼叫這個方法,看看會有什麼結果。