Timeline: get

需要授权

根据 ID 获取单个时间轴项。 查看示例

此端点会返回时间轴项的元数据,请参阅 mirror.attachments.get 以了解如何下载时间轴项的附件内容。

请求

HTTP 请求

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

参数

参数名称 说明
路径参数
id string 时间轴项的 ID。

授权

此请求需要获得以下至少一个范围的授权(详细了解身份验证和授权)。

范围
https://www.googleapis.com/auth/glass.timeline
https://www.googleapis.com/auth/glass.location

请求正文

使用此方法时请勿提供请求正文。

响应

如果成功,此方法将在响应正文中返回时间轴资源

示例

注意:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。

使用 Java 客户端库

import com.google.api.services.mirror.Mirror;
import com.google.api.services.mirror.model.Attachment;
import com.google.api.services.mirror.model.Contact;
import com.google.api.services.mirror.model.NotificationConfig;
import com.google.api.services.mirror.model.TimelineItem;

import java.io.IOException;

public class MyClass {
 
// ...

 
/**
   * Print some timeline item metadata information.
   *
   * @param service Authorized Mirror service.
   * @param itemId ID of the timeline item to print metadata information for.
   */

 
public static void printTimelineItemMetadata(Mirror service, String itemId) {
   
try {
     
TimelineItem timelineItem = service.timeline().get(itemId).execute();

     
System.out.println("Timeline item ID: " + timelineItem.getId());
     
if (timelineItem.getIsDeleted()) {
       
System.out.println("Timeline item has been deleted");
     
} else {
       
Contact creator = timelineItem.getCreator();
       
if (creator != null) {
         
System.out.println("Timeline item created by " + creator.getDisplayName());
       
}
       
System.out.println("Timeline item created on " + timelineItem.getCreated().toStringRfc3339());
       
System.out.println("Timeline item displayed on "
           
+ timelineItem.getDisplayTime().toStringRfc3339());
       
String inReplyTo = timelineItem.getInReplyTo();
       
if (inReplyTo != null && inReplyTo.length() > 0) {
         
System.out.println("Timeline item is a reply to " + inReplyTo);
       
}
       
String text = timelineItem.getText();
       
if (text != null && text.length() > 0) {
         
System.out.println("Timeline item has text: " + text);
       
}
       
for (Contact contact : timelineItem.getRecipients()) {
         
System.out.println("Timeline item is shared with: " + contact.getId());
       
}
       
NotificationConfig notification = timelineItem.getNotification();
       
if (notification != null) {
         
System.out.println("Notification delivery time: "
             
+ notification.getDeliveryTime().toStringRfc3339());
         
System.out.println("Notification level: " + notification.getLevel());
       
}
       
// See mirror.timeline.attachments.get to learn how to download the attachment's content.
       
for (Attachment attachment : timelineItem.getAttachments()) {
         
System.out.println("Attachment ID: " + attachment.getId());
         
System.out.println("  > Content-Type: " + attachment.getContentType());
       
}
     
}
   
} catch (IOException e) {
     
System.err.println("An error occurred: " + e);
   
}
 
}

 
// ...
}

使用 .NET 客户端库

using System;

using Google.Apis.Mirror.v1;
using Google.Apis.Mirror.v1.Data;

public class MyClass {
 
// ...

 
/// <summary>
 
/// Print some timeline item metadata information.
 
/// </summary>
 
/// <param name='service'>Authorized Mirror service.</param>
 
/// <param name='itemId'>
 
/// ID of the timeline item to print metadata information for.
 
/// </param>
 
public static void PrintTimelineItemMetadata(MirrorService service,
     
String itemId) {
   
try {
     
TimelineItem timelineItem = service.Timeline.Get(itemId).Fetch();

     
Console.WriteLine("Timeline item ID: " + timelineItem.Id);
     
if (timelineItem.IsDeleted.HasValue && timelineItem.IsDeleted.Value) {
       
Console.WriteLine("Timeline item has been deleted");
     
} else {
       
Contact creator = timelineItem.Creator;
       
if (creator != null) {
         
Console.WriteLine("Timeline item created by " + creator.DisplayName);
       
}
       
Console.WriteLine("Timeline item created on " + timelineItem.Created);
       
Console.WriteLine(
           
"Timeline item displayed on " + timelineItem.DisplayTime);
       
String inReplyTo = timelineItem.InReplyTo;
       
if (!String.IsNullOrEmpty(inReplyTo)) {
         
Console.WriteLine("Timeline item is a reply to " + inReplyTo);
       
}
       
String text = timelineItem.Text;
       
if (!String.IsNullOrEmpty(text)) {
         
Console.WriteLine("Timeline item has text: " + text);
       
}
       
foreach (Contact contact in timelineItem.Recipients) {
         
Console.WriteLine("Timeline item is shared with: " + contact.Id);
       
}
       
NotificationConfig notification = timelineItem.Notification;
       
if (notification != null) {
         
Console.WriteLine(
             
"Notification delivery time: " + notification.DeliveryTime);
         
Console.WriteLine("Notification level: " + notification.Level);
       
}
       
// See mirror.timeline.attachments.get to learn how to download the
       
// attachment's content.
       
foreach (Attachment attachment in timelineItem.Attachments) {
         
Console.WriteLine("Attachment ID: " + attachment.Id);
         
Console.WriteLine("  > Content-Type: " + attachment.ContentType);
       
}
     
}
   
} catch (Exception e) {
     
Console.WriteLine("An error occurred: " + e.Message);
   
}
 
}

 
// ...
}

使用 PHP 客户端库

/**
 * Print some timeline item metadata information.
 *
 * @param Google_MirrorService $service Authorized Mirror service.
 * @param string $itemId ID of the timeline item to print metadata
 *                       information for.
 */

function printTimelineItemMetadata($service, $itemId) {
 
try {
    $timelineItem
= $service->timeline->get($itemId);

   
print 'Timeline item ID: ' . $timelineItem->getId();
   
if ($timelineItem->getIsDeleted()) {
     
print 'Timeline item has been deleted';
   
} else {
      $creator
= $timelineItem->getCreator();
     
if ($creator != null) {
       
print 'Timeline item created by ' . $creator->getDisplayName();
     
}
     
print 'Timeline item created on ' . $timelineItem->getCreated();
     
print 'Timeline item displayed on ' . $timelineItem->getDisplayTime();
      $inReplyTo
= $timelineItem->getInReplyTo();
     
if ($inReplyTo != null) {
       
print 'Timeline item is a reply to ' . $inReplyTo;
     
}
      $text
= $timelineItem->getText();
     
if ($text != null) {
       
print 'Timeline item has text: ' . $text;
     
} else {
       
foreach ($timelineItem->getHtml() as $html) {
         
print 'Timeline item has HTML: ' . $html;
       
}
     
}
     
foreach ($timelineItem->getRecipients() as $contacts) {
       
print 'Timeline item is shared with: ' . $contact->getId();
     
}
      $notification
= $timelineItem->getNotification();
     
if ($notification != null) {
       
print 'Notification delivery time: ' . $notification->getDeliveryTime();
       
print 'Notification level: ' . $notification->getLevel();
     
}
   
}
 
} catch (Exception $e) {
   
print 'An error occurred: ' . $e->getMessage();
 
}
}

使用 Python 客户端库

from apiclient import errors
# ...

def print_timeline_item_metadata(service, timeline_id):
 
"""Print some timeline item metadata information.

  Args:
    service: Authorized Mirror service.
    item_id: ID of the timeline item to print metadata information for.
  """

 
try:
    timeline_item
= service.timeline().get(id=item_id).execute()

   
print 'Timeline item ID:  %s' % timeline_item.get('id')
   
if timeline_item.get('isDeleted'):
     
print 'Timeline item has been deleted'
   
else:
      creator
= timeline_item.get('creator')
     
if creator:
       
print 'Timeline item created by  %s' % creator.get('displayName')
     
print 'Timeline item created on  %s' % timeline_item.get('created')
     
print 'Timeline item displayed on %s' % timeline_item.get('displayTime')
      in_reply_to
= timeline_item.get('inReplyTo')
     
if in_reply_to:
       
print 'Timeline item is a reply to  %s' % in_reply_to
      text
= timeline_item.get('text')
     
if text:
       
print 'Timeline item has text:  %s' % text
     
for contact in timeline_item.get('recipients', []):
       
print 'Timeline item is shared with:  %s' % contact.get('id')
      notification
= timeline_item.get('notification')
     
if notification:
       
print 'Notification delivery time: %s' % (
            notification
.get('deliveryTime'))
       
print 'Notification level:  %s' % notification.get('level')
     
# See mirror.timeline.attachments.get to learn how to download the
     
# attachment's content.
     
for attachment in timeline_item.get('attachments', []):      
       
print 'Attachment ID: %s' % attachment.get('id')
       
print '  > Content-Type: %s' % attachment.get('contentType')
 
except errors.HttpError, error:
   
print 'An error occurred: %s' % error

使用 Ruby 客户端库

###
# Print some Timeline Item metadata information.
#
# @param [Google::APIClient] client
#   Authorized client instance.
# @param [string] item_id
#   ID of the timeline item to print metadata information for.
# @return nil
def print_timeline_item_metadata(client, item_id)
  mirror
= client.discovered_api('mirror', 'v1')
  result
= client.execute(
   
:api_method => mirror.timeline.get,
   
:parameters => { 'id' => item_id })
 
if result.success?
    timeline_item
= result.data
    puts
"Timeline item ID:  #{timeline_item.id}"
   
if timeline_item.is_deleted
      puts
"Timeline item has been deleted"
   
else
      creator
= timeline_item.creator
     
if creator
        puts
"Timeline item created by #{creator.display_name}"
     
end
      puts
"Timeline created on #{timeline_item.created}"
      puts
"Timeline displayed on #{timeline_item.display_time}"
      in_reply_to
= timeline_item.in_reply_to
     
if in_reply_to
        puts
"Timeline item is a reply to #{in_reply_to}"
     
end
      text
= timeline_item.text
     
if text
        puts
"Timeline item has text: #{text}"
     
end
      html
= timeline_item.html
     
if html
        puts
"Timeline item has html: #{html}"
     
end
      timeline_item
.recipients.each do |contact|
        puts
"Timeline item is shared with:  #{contact.id}"
     
end
      notification
= timeline_item.notification
     
if notification
        puts
"Notification delivery time: #{notification.delivery_time}"
        puts
"Notification level: #{notification.level}"
     
end
   
end
 
else
    puts
"An error occurred: #{result.data['error']['message']}"
 
end
end

使用 Go 客户端库

import (
        "code.google.com/p/google-api-go-client/mirror/v1"
        "fmt"
)

// PrintTimelineItemMetadata some timeline item metadata information.
func PrintTimelineItemMetadata(g *mirror.Service, itemId string) error {
        t, err := g.Timeline.Get(itemId).Do()
        if err != nil {
                fmt.Printf("An error occurred: %v\n", err)
                return err
        }
        fmt.Printf("Timeline item ID: %s\n", t.Id)
        if t.IsDeleted {
                fmt.Printf("Timeline item has been deleted\n")
        } else {
                if t.Creator != nil {
                        fmt.Printf("Timeline item created by %s\n", t.Creator.DisplayName)
                }
                fmt.Printf("Timeline item created on %s\n", t.Created)
                fmt.Printf("Timeline item displayed on %s\n", t.DisplayTime)
                if t.InReplyTo != "" {
                        fmt.Printf("Timeline item is a reply to %s\n", t.InReplyTo)
                }
                if t.Text != "" {
                        fmt.Printf("Timeline item has text: %s\n", t.Text)
                }
                for _, s := range t.Recipients {
                        fmt.Printf("Timeline item is shared with: %s\n", s.Id)
                }
                if t.Notification != nil {
                        n := t.Notification
                        fmt.Printf("Notification delivery time: %s\n", n.DeliveryTime)
                        fmt.Printf("Notification level: %s\n", n.Level)
                }
                for _, a := range t.Attachments {
                        fmt.Printf("Attachment ID: %s\n", a.Id)
                        fmt.Printf("  > Content-Type: %s\n", a.ContentType)
                }
        }
        return nil
}

不使用客户端库。

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