需要授权
检索用户的位置列表。查看示例。
请求
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 |
位置列表。 |
示例
注意:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。
Java
使用 Java 客户端库。
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