נדרשת הרשאה
מאחזר רשימה של פריטי ציר הזמן עבור המשתמש המאומת. לעיון בדוגמה
שליחת בקשה
בקשת HTTP
GET https://www.googleapis.com/mirror/v1/timeline
פרמטרים
שם הפרמטר | ערך | תיאור |
---|---|---|
פרמטרים אופציונליים של שאילתה | ||
bundleId |
string |
אם תספקו את הפריטים האלה, יוחזרו רק פריטים עם ה-bundleId הנתון. |
includeDeleted |
boolean |
אם True, תוחזר רשומות מצבה עבור פריטים שנמחקו. |
maxResults |
unsigned integer |
המספר המקסימלי של פריטים להכללה בתגובה, המשמש לדפדוף. |
orderBy |
string |
המדיניות קובעת את הסדר שבו יוחזרו הפריטים בציר הזמן.
הערכים הקבילים הם:
|
pageToken |
string |
אסימון לדף התוצאות להחזרה. |
pinnedOnly |
boolean |
אם True, רק פריטים מוצמדים יוחזרו. |
sourceItemId |
string |
אם יסופקו, רק פריטים שיש להם את הפרמטר itemItemId יוחזרו. |
הרשאה
לבקשה הזו נדרשת הרשאה עם לפחות אחד מהיקפי ההרשאות הבאים (מידע נוסף על אימות והרשאה).
היקף |
---|
https://www.googleapis.com/auth/glass.timeline |
https://www.googleapis.com/auth/glass.location |
גוף הבקשה
אין להזין גוף בקשה בשיטה זו.
תשובה
אם התגובה מוצלחת, שיטה זו תחזיר גוף תגובה בעל המבנה הבא:
{ "kind": "mirror#timeline", "nextPageToken": string, "items": [ timeline Resource ] }
שם הנכס | ערך | תיאור | הערות |
---|---|---|---|
kind |
string |
סוג המשאב. תמיד mirror#timeline . |
|
nextPageToken |
string |
האסימון של הדף הבא. מזינים אותו כפרמטר pageToken בבקשה לאחזור דף התוצאות הבא. |
|
items[] |
list |
פריטים בציר הזמן. |
דוגמאות
הערה: דוגמאות הקוד הזמינות לשיטה זו לא מייצגות את כל שפות התכנות הנתמכות (רשימת השפות הנתמכות זמינה בדף של ספריות המשתמשים).
Java
משתמש בספריית הלקוחות של Java.
import com.google.api.services.mirror.Mirror; import com.google.api.services.mirror.Mirror.Timeline; import com.google.api.services.mirror.model.TimelineItem; import com.google.api.services.mirror.model.TimelineListResponse; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class MyClass { // ... /** * Retrieve all timeline items for the current user. * * @param service Authorized Mirror service. * @return Collection of timeline items on success, {@code null} otherwise. */ public static List<TimelineItem> retrieveAllTimelineItems(Mirror service) { List<TimelineItem> result = new ArrayList<TimelineItem>(); try { Timeline.List request = service.timeline().list(); do { TimelineListResponse timelineItems = request.execute(); if (timelineItems.getItems() != null && timelineItems.getItems().length() > 0) { result.addAll(timelineItems.getItems()); request.setPageToken(timelineItems.getNextPageToken()); } else { break; } } while (request.getPageToken() != null && request.getPageToken().length() > 0); } catch (IOException e) { System.err.println("An error occurred: " + e); return null; } return result; } // ... }
.NET
משתמש בספריית הלקוח מסוג .NET
using System; using System.Collections.Generic; using Google.Apis.Mirror.v1; using Google.Apis.Mirror.v1.Data; public class MyClass { // ... /// <summary> /// Retrieve all timeline items for the current user. /// </summary> /// <param name='service'>Authorized Mirror service.</param> /// <returns> /// List of timeline items on success, null otherwise. /// </returns> public static List<TimelineItem> RetrieveAllTimelineItems( MirrorService service) { List<TimelineItem> result = new List<TimelineItem>(); try { TimelineResource.ListRequest request = service.Timeline.List(); do { TimelineListResponse timelineItems = request.Fetch(); if (timelineItems.Items != null && timelineItems.Items.Length > 0) { result.AddRange(timelineItems.Items); request.PageToken = timelineItems.NextPageToken; } else { break; } } while (!String.IsNullOrEmpty(request.PageToken)); } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); return null; } return result; } // ... }
PHP
משתמש בספריית הלקוח של PHP.
/** * Retrieve all timeline items for the current user. * * @param Google_MirrorService $service Authorized Mirror service. * @return Array List of Google_TimelineItem resources on success, * null otherwise. */ function retrieveAllTimelineItems($service) { try { $result = array(); $pageToken = null; do { $optParams = array(); if ($pageToken) { $optParams['pageToken'] = $pageToken; } $timelineItems = $service->timeline->listTimeline($optParams); if (!empty(timelineItems->getItems()) { $result = array_merge($result, $timelineItems->getItems()); $pageToken = $timelineItems->getNextPageToken(); } else { break; } } while ($pageToken); return $result; } catch (Exception $e) { print 'An error occurred: ' . $e->getMessage(); return null; } }
Python
משתמש בספריית הלקוחות של Python.
from apiclient import errors # ... def retrieve_all_timeline_tems(service): """Retrieve all timeline items for the current user. Args: service: Authorized Mirror service. Returns: Collection of timeline items on success, None otherwise. """ result = [] request = service.timeline().list() while request: try: timeline_items = request.execute() items = timeline_items.get('items', []) if items: result.extend(timeline_items.get('items', [])) request = service.timeline().list_next(request, timeline_items) else: # No more items to retrieve. break except errors.HttpError, error: print 'An error occurred: %s' % error break return result
Ruby
משתמש בספריית הלקוחות של Rubby.
## # Retrieve all Timeline Items for the current user. # # @param [Google::APIClient] client # Authorized client instance. # @return [Array] # List of timeline items. def retrieve_all_timeline_items(client) mirror = client.discovered_api('mirror', 'v1') result = Array.new page_token = nil begin parameters = {} if page_token.to_s != '' parameters['pageToken'] = page_token end api_result = client.execute( :api_method => mirror.timeline.list, :parameters => parameters) if api_result.success? timeline_items = api_result.data if timeline_items.items.empty? page_token = nil else result.concat(timeline_items.items) page_token = timeline_items.next_page_token end else puts "An error occurred: #{result.data['error']['message']}" page_token = nil end end while page_token.to_s != '' result end
Go
נעשה שימוש בספריית הלקוחות של Go.
import ( "code.google.com/p/google-api-go-client/mirror/v1" "fmt" ) // RetrieveAllTimelineItems retrieves all timeline items for the current user. func RetrieveAllTimelineItems(g *mirror.Service) ([]*mirror.TimelineItem, error) { r := []*mirror.TimelineItem{} req := g.Timeline.List() for req != nil { t, err := req.Do() if err != nil { fmt.Printf("An error occurred: %v\n", err) return nil, err } if t.Items != nil && len(t.Items) > 0 { r = append(r, t.Items...) req.PageToken(t.NextPageToken) } else { req = nil } } return r, nil }
HTTP גולמי
לא נעשה שימוש בספריית לקוח.
GET /mirror/v1/timeline HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer auth token