需要授權
傳回時間軸項目的附件清單。 請點選此處查看範例。
要求
HTTP 要求
GET https://www.googleapis.com/mirror/v1/timeline/itemId/attachments
參數
| 參數名稱 | 值 | 說明 |
|---|---|---|
| 路徑參數 | ||
itemId |
string |
應列出附件的時間軸項目 ID。 |
授權
此要求需要獲得下列範圍的授權 (進一步瞭解驗證和授權)。
| 範圍 |
|---|
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 用戶端程式庫。
##
# 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