Locations: list

승인 필요

사용자의 위치 목록을 검색합니다. 예를 참조하세요.

요청

HTTP 요청

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

확인할 내용

이 요청에는 다음 범위 중 최소 하나를 사용하여 인증이 필요합니다. (인증 및 승인에 대해 자세히 알아보기)

범위
https://www.googleapis.com/auth/glass.timeline
https://www.googleapis.com/auth/glass.location

요청 본문

이 메소드를 사용할 때는 요청 본문을 제공하지 마세요.

응답

요청에 성공할 경우 이 메소드는 다음과 같은 구조의 응답 본문을 반환합니다.

{
  "kind": "mirror#locationsList",
  "items": [
    locations Resource
  ]
}
속성 이름 설명 메모
kind string 리소스 유형 항상 mirror#locationsList입니다.
items[] list 위치 목록입니다.

참고: 이 메서드에 제공되는 코드 예시가 지원되는 모든 프로그래밍 언어를 나타내는 것은 아닙니다. 지원되는 언어 목록은 클라이언트 라이브러리 페이지를 참조하세요.

자바

자바 클라이언트 라이브러리를 사용합니다.

import com.google.api.services.mirror.Mirror;
import com.google.api.services.mirror.model.Location;
import com.google.api.services.mirror.model.LocationsListResponse;

import java.io.IOException;

public class MyClass {
  // ...

  /**
   * Print information about all the known locations for the current user.
   * 
   * @param service Authorized Mirror service.
   */
  public static void printAllLocations(Mirror service) {
    try {
      LocationsListResponse locations = service.locations().list().execute();

      for (Location location : locations.getItems()) {
        System.out.println("Location recorded on: " + location.getTimestamp());
        System.out.println("  > Lat: " + location.getLatitude());
        System.out.println("  > Long: " + location.getLongitude());
        System.out.println("  > Accuracy: " + location.getAccuracy() + " meters");
      }
    } catch (IOException e) {
      System.err.println("An error occurred: " + e);
    }
  }

  // ...
}

.NET

.NET 클라이언트 라이브러리를 사용합니다.

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

public class MyClass {
  // ...

  /// <summary>
  /// Print information about all the known locations for the current user.
  /// </summary>
  /// <param name="service">Authorized Mirror service.</param>
  public static void PrintAllLocations(MirrorService service) {
    try {
      LocationsListResponse locations = service.Locations.List().Fetch();

      foreach (Location location in locations.Items) {
        Console.WriteLine("Location recorded on: " + location.Timestamp);
        Console.WriteLine("  > Lat: " + location.Latitude);
        Console.WriteLine("  > Long: " + location.Longitude);
        Console.WriteLine("  > Accuracy: " + location.Accuracy + " meters");
      }
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
  }

  // ...
}

PHP

PHP 클라이언트 라이브러리를 사용합니다.

/**
 * Print information about all the known locations for the current user.
 *
 * @param Google_MirrorService $service Authorized Mirror service.
 */
function printAllLocations($service) {
  try {
    $locations = $service->locations->listLocations();

    foreach ($locations->getItems() as $location) {
      print 'Location recorded on: ' . $location->getTimestamp() . "\n";
      print '  > Lat: ' . $location->getLatitude() . "\n";
      print '  > Long: ' . $location->getLongitude() . "\n";
      print '  > Accuracy: ' . $location->getAccuracy() . " meters\n";
    }
  } catch (Exception $e) {
    print 'An error occurred: ' . $e->getMessage();
  }
}

Python

Python 클라이언트 라이브러리를 사용합니다.

from apiclient import errors
# ...

def print_all_locations(service):
  """Print information about all the known locations for the current user.

  Args:
    service: Authorized Mirror service.
  """
  try:
    location = service.locations().list().execute()

    for location in location.get('items', []):
      print 'Location recorded on: %s' % location.get('timestamp')
      print '  > Lat: %s' % location.get('latitude')
      print '  > Long: %s' % location.get('longitude')
      print '  > Accuracy: %s meters' % location.get('accuracy')
  except errors.HttpError, e:
    print 'An error occurred: %s' % e

Ruby

Ruby 클라이언트 라이브러리를 사용합니다.

##
# Print information about all the known locations for the current user.
#
# @param [Google::APIClient] client
#   Authorized client instance.
# @return nil
def print_all_locations(client)
  mirror = client.discovered_api('mirror', 'v1')
  result = client.execute(:api_method => mirror.locations.list)
  if result.success?
    locations = result.data
    locations.items.each do |location|
      puts "Location recorded on: #{location.timestamp}"
      puts "  > Lat: #{location.latitude}"
      puts "  > Long: #{location.longitude}"
      puts "  > Accuracy: #{location.accuracy} meters"
    end
  else
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

원시 HTTP

클라이언트 라이브러리를 사용하지 않습니다.

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