Timeline: list

Yêu cầu uỷ quyền

Truy xuất danh sách các mục trong dòng thời gian cho người dùng đã xác thực. Xem ví dụ.

Yêu cầu

Yêu cầu HTTP

GET https://www.googleapis.com/mirror/v1/timeline

Các tham số

Tên thông số Giá trị Mô tả
Tham số truy vấn không bắt buộc
bundleId string Nếu được cung cấp, chỉ những mặt hàng có bundleId nhất định mới được trả về.
includeDeleted boolean Nếu đúng, bản ghi tombstone cho các mục đã xóa sẽ được trả về.
maxResults unsigned integer Số mục tối đa cần có trong phản hồi, được dùng để phân trang.
orderBy string Kiểm soát thứ tự trả về các mục trong dòng thời gian.

Các giá trị được chấp nhận là:
  • "displayTime": Kết quả sẽ được sắp xếp theo displayTime (mặc định). Trình tự này được sử dụng trong dòng thời gian trên thiết bị.
  • "writeTime": Kết quả sẽ được sắp xếp theo thời điểm ghi kết quả gần đây nhất vào kho dữ liệu.
pageToken string Mã thông báo của trang kết quả trả về.
pinnedOnly boolean Nếu đúng, chỉ các mục được ghim mới được trả về.
sourceItemId string Nếu được cung cấp, chỉ trả về các mục có sourceItemId.

Ủy quyền

Yêu cầu này yêu cầu uỷ quyền có ít nhất một trong các phạm vi sau (đọc thêm về xác thực và cấp phép).

Phạm vi
https://www.googleapis.com/auth/glass.timeline
https://www.googleapis.com/auth/glass.location

Nội dung yêu cầu

Đừng cung cấp nội dung yêu cầu bằng phương thức này.

Phản hồi

Nếu thành công, phương thức này sẽ trả về nội dung phản hồi với cấu trúc sau:

{
  "kind": "mirror#timeline",
  "nextPageToken": string,
  "items": [
    timeline Resource
  ]
}
Tên tài sản Giá trị Mô tả Ghi chú
kind string Loại tài nguyên. Đây luôn là mirror#timeline.
nextPageToken string Mã thông báo trang tiếp theo. Cung cấp tham số này dưới dạng tham số pageToken trong yêu cầu truy xuất trang kết quả tiếp theo.
items[] list Các mục trong tiến trình.

Ví dụ

Lưu ý: Các đoạn mã mẫu của phương thức này không phải là ví dụ cho mọi ngôn ngữ lập trình được hỗ trợ (xem trang thông tin về các thư viện dùng cho ứng dụng để biết danh sách các ngôn ngữ được hỗ trợ).

Java

Sử dụng thư viện ứng dụng 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

Sử dụng thư viện ứng dụng.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

Sử dụng thư viện ứng dụngPHP.

/**
 * 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

Sử dụng thư viện ứng dụng 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

Sử dụng thư viện ứng dụng Ruby.

##
# 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

Sử dụng Thư viện ứng dụng 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 thô

Không sử dụng thư viện ứng dụng.

GET /mirror/v1/timeline HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer auth token