Timeline.attachments: get

অনুমোদন প্রয়োজন

আইটেম আইডি এবং সংযুক্তি আইডি দ্বারা একটি টাইমলাইন আইটেমে একটি সংযুক্তি পুনরুদ্ধার করে৷ একটি উদাহরণ দেখুন

অনুরোধ

HTTP অনুরোধ

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

পরামিতি

পরামিতি নাম মান বর্ণনা
পাথ প্যারামিটার
attachmentId string সংযুক্তির আইডি।
itemId string সংযুক্তিটি টাইমলাইন আইটেমের আইডি।

অনুমোদন

এই অনুরোধের জন্য নিম্নলিখিত সুযোগের সাথে অনুমোদনের প্রয়োজন ( প্রমাণিকরণ এবং অনুমোদন সম্পর্কে আরও পড়ুন )।

ব্যাপ্তি
https://www.googleapis.com/auth/glass.timeline

শরীরের অনুরোধ

এই পদ্ধতির সাথে একটি অনুরোধ সংস্থা সরবরাহ করবেন না।

প্রতিক্রিয়া

সফল হলে, এই পদ্ধতিটি প্রতিক্রিয়া বডিতে একটি Timeline.attachments রিসোর্স প্রদান করে।

উদাহরণ

দ্রষ্টব্য: এই পদ্ধতির জন্য উপলব্ধ কোড উদাহরণগুলি সমস্ত সমর্থিত প্রোগ্রামিং ভাষার প্রতিনিধিত্ব করে না (সমর্থিত ভাষার তালিকার জন্য ক্লায়েন্ট লাইব্রেরি পৃষ্ঠা দেখুন)।

জাভা

জাভা ক্লায়েন্ট লাইব্রেরি ব্যবহার করে।

import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpResponse;
import com.google.api.services.mirror.Mirror;
import com.google.api.services.mirror.model.Attachment;

import java.io.IOException;
import java.io.InputStream;

public class MyClass {
  // ...

  /**
   * Print an attachment's metadata.
   * 
   * @param service Authorized Mirror service.
   * @param itemId ID of the timeline item the attachment belongs to.
   * @param attachmentId ID of the attachment to print metadata for.
   */
  public static void printAttachmentMetadata(Mirror service, String itemId, String attachmentId) {
    try {
      Attachment attachment = service.timeline().attachments().get(itemId, attachmentId).execute();

      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);
    }
  }

  /**
   * Download a timeline items's attachment.
   * 
   * @param service Authorized Mirror service.
   * @param itemId ID of the timeline item to download the attachment for.
   * @param attachment Attachment to download content for.
   * @return The attachment content on success, {@code null} otherwise.
   */
  public static InputStream downloadAttachment(Mirror service, String itemId, Attachment attachment) {
    try {
      HttpResponse resp =
          service.getRequestFactory().buildGetRequest(new GenericUrl(attachment.getContentUrl()))
              .execute();
      return resp.getContent();
    } catch (IOException e) {
      // An error occurred.
      e.printStackTrace();
      return null;
    }
  }

  // ...
}

.নেট

.NET ক্লায়েন্ট লাইব্রেরি ব্যবহার করে।

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

public class MyClass {
  // ...

  /// <summary>
  /// Print an attachment's metadata.
  /// </summary>
  /// <param name="service">Authorized Mirror service.</param>
  /// <param name="itemId">ID of the timeline item the attachment belongs to.</param>
  /// <param name="attachmentId">ID of the attachment to print metadata for.</param>
  public static void PrintAttachmentMetadata(
      MirrorService service, String itemId, String attachmentId) {
    try {
      Attachment attachment = service.Timeline.Attachments.Get(itemId, attachmentId).Fetch();

      Console.WriteLine("Attachment content type: " + attachment.ContentType);
      Console.WriteLine("Attachment content URL: " + attachment.ContentUrl);
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
  }
  
  /// <summary>
  /// Download a timeline items's attachment.
  /// </summary>
  /// <param name="service">Authorized Mirror service.</param>
  /// <param name="attachment">Attachment to download content for.</param>
  /// <returns>Attachment's content if successful, null otherwise.</returns>
  public static System.IO.Stream DownloadAttachment(
      MirrorService service, Attachment attachment) {
    try {
      HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
        new Uri(attachment.ContentUrl));
      service.Authenticator.ApplyAuthenticationToRequest(request);
      HttpWebResponse response = (HttpWebResponse)request.GetResponse();
      if (response.StatusCode == HttpStatusCode.OK) {
        return response.GetResponseStream();
      } else {
        Console.WriteLine(
          "An error occurred: " + response.StatusDescription);
        return null;
      }
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
      return null;
    }
  }

  // ...
}

পিএইচপি

পিএইচপি ক্লায়েন্ট লাইব্রেরি ব্যবহার করে।

/**
 * Print an attachment's metadata.
 *
 * @param Google_MirrorService $service Authorized Mirror service.
 * @param string $itemId ID of the timeline item the attachment belongs to.
 * @param string $attachmentId ID of the attachment to print metadata for.
 */
function printAttachmentMetadata($service, $itemId, $attachmentId) {
  try {
    $attachment = $service->timeline_attachments->get($itemId, $attachmentId);

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

/**
 * Download an attachment's content.
 *
 * @param string $timelineId ID of the timeline item the attachment belongs to.
 * @param Google_Attachment $attachment Attachment's metadata.
 * @return string The attachment's content if successful, null otherwise.
 */
function downloadAttachment($itemId, $attachment) {
  $request = new Google_HttpRequest(
      $attachment->getContentUrl(), 'GET', null, null);
  $httpRequest = Google_Client::$io->authenticatedRequest($request);
  if ($httpRequest->getResponseHttpCode() == 200) {
    return $httpRequest->getResponseBody();
  } else {
    // An error occurred.
    return null;
  }
}

পাইথন

পাইথন ক্লায়েন্ট লাইব্রেরি ব্যবহার করে।

from apiclient import errors
# ...

def print_attachment_metadata(service, item_id, attachment_id):
  """Print an attachment's metadata

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

def download_attachment(service, attachment):
  """Download an attachment's content

  Args:
    service: Authorized Mirror service.
    attachment: Attachment's metadata.
  Returns:
    Attachment's content if successful, None otherwise.
  """
  resp, content = service._http.request(attachment['contentUrl'])
  if resp.status == 200:
    return content
  else:
    print 'An error occurred: %s' % resp
    return None

রুবি

রুবি ক্লায়েন্ট লাইব্রেরি ব্যবহার করে।

##
# Print an attachment's metadata.
#
# @param [Google::APIClient] client
#   Authorized client instance.
# @param [String] item_id
#   ID of the timeline item the attachment belongs to.
# @param [String] attachment_id
#   ID of the attachment to print metadata for.
# @return nil
def print_attachment_metadata(client, item_id, attachment_id)
  mirror = client.discovered_api('mirror', 'v1')
  result = client.execute(
    :api_method => mirror.timeline.attachments.get,
    :parameters => {
      'itemId' => item_id,
      'attachmentId' => attachment_id})
  if result.success?
    attachment = result.data
    puts "Attachment content type: #{attachment.content_type}"
    puts "Attachment content url: #{attachment.content_url}"
  else
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

##
# Download an attachment's content
#
# @param [Google::APIClient] client
#   Authorized client instance
# @param [Google::APIClient::Schema::Mirror::V1::Attachment]
#   Attachment instance
# @return
#   Attachment's content if successful, nil otherwise
def download_attachment(client, attachment)
  result = client.execute(:uri => attachment.content_url)
  if result.success?
    return result.body
  else
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

কাঁচা HTTP

একটি ক্লায়েন্ট লাইব্রেরি ব্যবহার করে না।

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