Timeline.attachments: list

ต้องมีการให้สิทธิ์

แสดงรายการของไฟล์แนบสําหรับรายการไทม์ไลน์ ดูตัวอย่าง

ส่งคำขอ

คำขอ HTTP

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

พารามิเตอร์

ชื่อพารามิเตอร์ ค่า คำอธิบาย
พารามิเตอร์เส้นทาง
itemId string รหัสของรายการไทม์ไลน์ที่ควรแสดงไฟล์แนบ

การให้สิทธิ์

คําขอนี้ต้องมีการให้สิทธิ์ขอบเขตต่อไปนี้ (อ่านเพิ่มเติมเกี่ยวกับการตรวจสอบสิทธิ์และการให้สิทธิ์)

ขอบเขต
https://www.googleapis.com/auth/glass.timeline

เนื้อหาของคำขอ

อย่าให้เนื้อหาคําขอด้วยวิธีนี้

คำตอบ

หากสําเร็จ วิธีนี้จะแสดงผลเนื้อหาการตอบกลับที่มีโครงสร้างต่อไปนี้

{
  "kind": "mirror#attachmentsList",
  "items": [
    timeline.attachments Resource
  ]
}
ชื่อพร็อพเพอร์ตี้ ค่า คำอธิบาย หมายเหตุ
kind string ประเภทของทรัพยากร นี่เป็น mirror#attachmentsList เสมอ
items[] list รายการไฟล์แนบ

ตัวอย่าง

หมายเหตุ: ตัวอย่างโค้ดที่มีสำหรับวิธีการนี้ไม่ได้แสดงถึงภาษาโปรแกรมที่รองรับทั้งหมด (ดูรายการภาษาที่รองรับได้ในหน้าไลบรารีของไคลเอ็นต์)

Java

ใช้ไลบรารีของไคลเอ็นต์ Java

import com.google.api.services.mirror.Mirror;
import com.google.api.services.mirror.model.Attachment;
import com.google.api.services.mirror.model.AttachmentsListResponse;

import java.io.IOException;

public class MyClass {
  // ...

  /**
   * Print all attachments' metadata.
   * 
   * @param service Authorized Mirror service.
   * @param itemId ID of the timeline item the attachments belong to.
   */
  public static void printAllAttachmentsMetadata(Mirror service, String itemId) {
    try {
      AttachmentsListResponse attachments = service.timeline().attachments().list(itemId).execute();

      for (Attachment attachment : attachments.getItems()) {
        System.out.println("Attachment content type: " + attachment.getContentType());
        System.out.println("Attachment content URL: " + attachment.getContentUrl());
      }
    } catch (IOException e) {
      System.out.println("An error occured: " + e);
    }

  }

  // ...
}

.NET

ใช้ไลบรารีของไคลเอ็นต์ .NET

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

public class MyClass {
  // ...

  /// <summary>
  /// Print all attachments' metadata.
  /// </summary>
  /// <param name="service">Authorized Mirror service.</param>
  /// <param name="itemId">ID of the timeline item the attachments belong to.</param>
  public static void PrintAllAttachmentsMetadata(MirrorService service, String itemId) {
    try {
      AttachmentsListResponse attachments = service.Timeline.Attachments.List(itemId).Fetch();

      foreach (Attachment attachment in attachments.Items) {
        Console.WriteLine("Attachment content type: " + attachment.ContentType);
        Console.WriteLine("Attachment content URL: " + attachment.ContentUrl);
      }
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
  }

  // ...
}

PHP

ใช้ไลบรารีของไคลเอ็นต์ PHP

/**
 * Print all attachments' metadata.
 *
 * @param Google_MirrorService $service Authorized Mirror service.
 * @param string $itemId ID of the timeline item the attachments belong to.
 */
function printAllAttachmentsMetadata($service, $itemId) {
  try {
    $attachments = $service->timeline_attachments->listTimelineAttachments(
        $itemId);

    foreach ($attachments->getItems() as $attachment) {
      print "Attachment content type: " . $attachment->getContentType() . "\n";
      print "Attachment content URL: " . $attachment->getContentUrl() . "\n";
    }
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
}

Python

ใช้ไลบรารีของไคลเอ็นต์ Python

from apiclient import errors
# ...

def print_all_attachments_metadata(service, item_id):
  """Print all attachments' metadata.

  Args:
    service: Authorized Mirror service.
    item_id: ID of the timeline item the attachments belong to.
  """
  try:
    attachments = service.timeline().attachments().list(
        itemId=item_id).execute()
    for attachment in attachments.get('items', []):
      print 'Attachment content type: %s' % attachment['contentType']
      print 'Attachment content URL: %s' % attachment['contentUrl']
  except errors.HttpError, error:
    print 'An error occurred: %s' % error

Ruby

ใช้ไลบรารีของไคลเอ็นต์ Ruby

##
# Print all attachments' metadata.
#
# @param [Google::APIClient] client
#   Authorized client instance.
# @param [String] item_id
#   ID of the timeline item the attachments belong to.
# @return nil
def print_all_attachments_metadata(client, item_id)
  mirror = client.discovered_api('mirror', 'v1')
  result = client.execute(
    :api_method => mirror.timeline.attachments.list,
    :parameters => { 'itemId' => item_id })
  if result.success?
    attachments = result.data
    attachments.items.each do |attachment|
      puts "Attachment content type: #{attachment.content_type}"
      puts "Attachment content URL: #{attachment.content_url}"
    end
  else
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

HTTP ไฟล์ข้อมูล

ไม่ใช้ไลบรารีของไคลเอ็นต์

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