Contacts: get
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
需要授权
根据 ID 获取单个联系人。
查看示例。
请求
HTTP 请求
GET https://www.googleapis.com/mirror/v1/contacts/id
参数
参数名称 |
值 |
说明 |
路径参数 |
id |
string |
联系人的 ID。
|
授权
此请求需要获得下列范围的授权(详细了解身份验证和授权)。
范围 |
https://www.googleapis.com/auth/glass.timeline |
请求正文
使用此方法时请勿提供请求正文。
示例
注意:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。
Java
使用 Java 客户端库。
import com.google.api.services.mirror.Mirror;
import com.google.api.services.mirror.model.Contact;
import java.io.IOException;
public class MyClass {
// ...
/**
* Print information for a contact.
*
* @param service Authorized Mirror service.
* @param contactId ID of the Contact to print information for.
*/
public static void printContact(Mirror service, String contactId) {
try {
Contact contact = service.contacts().get(contactId).execute();
System.out.println("Contact displayName: " + contact.getDisplayName());
if (contact.getImageUrls() != null) {
for (String imageUrl : contact.getImagesUrls()) {
System.out.println("Contact imageUrl: " + imageUrl);
}
}
} 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 for a contact.
/// </summary>
/// <param name='service'>Authorized Mirror service</param>
/// <param name='contactId'>
/// ID of the Contact to print information for.
/// </param>
public static void PrintContact(MirrorService service,
String contactId) {
try {
Contact contact = service.Contacts.Get(contactId).Fetch();
Console.WriteLine(
"Contact displayName: " + contact.DisplayName);
if (contact.ImageUrls != null) {
foreach (String imageUrl in contact.ImageUrls) {
Console.WriteLine("Contact imageUrl: " + imageUrl);
}
}
} catch (Exception e) {
Console.WriteLine("An error occurred: " + e.Message);
}
}
// ...
}
PHP
使用 PHP 客户端库。
/*
* Print information for a contact.
*
* @param Google_MirrorService $service Authorized Mirror service.
* @param string $contactId ID of the Contact to print information for.
*/
function printContact($service, $contactId) {
try {
$contact = $service->contacts->get($contactId);
print 'Contact displayName: ' . $contact->getDisplayName();
if ($contact->getImageUrls() != null) {
foreach ($contact->getImageUrls() as $imageUrl) {
print 'Contact imageUrl: ' . $imageUrl;
}
}
} catch (Exception $e) {
print 'An error occurred: ' . $e->getMessage();
}
}
Python
使用 Python 客户端库。
from apiclient import errors
# ...
def print_contact(service, contact_id):
"""Print information for a contact.
Args:
service: Authorized Mirror service.
contact_id: ID of the Contact to print information for.
"""
try:
contact = service.contacts().get(id= contact_id).execute()
print 'Contact displayName: %s' % contact.get('displayName')
for image_url in contact.get('imageUrls', []):
print 'Contact imageUrl: %s' % image_url
except errors.HttpError, error:
print 'An error occurred: %s' % error
Ruby
使用 Ruby 客户端库。
##
# Print information for a contact.
#
# @param [Google::APIClient] client
# Authorized client instance.
# @param [String] contact_id
# ID of the contact to print information for.
# @return nil
def print_contact(client, contact_id)
mirror = client.discovered_api('mirror', 'v1')
result = client.execute(
:api_method => mirror.contacts.get,
:parameters => { 'id' => contact_id })
if result.success?
contact = result.data
puts "Contact displayName: #{contact.displayName}"
contact.image_urls.each do |image_url|
puts "Contact imageUrl: #{image_url}"
end
else
puts "An error occurred: #{result.data['error']['message']}"
end
end
Go
使用 Go 客户端库。
import (
"code.google.com/p/google-api-go-client/mirror/v1"
"fmt"
)
// PrintContact prints information for a contact.
func PrintContact(g *mirror.Service, contactId string) error {
s, err := g.Contacts.Get(contactId).Do()
if err != nil {
fmt.Printf("An error occurred: %v\n", err)
return err
}
fmt.Printf("Contact displayName: %s\n", s.DisplayName)
for _, i := range s.ImageUrls {
fmt.Printf("Contact imageUrl: %s\n", i)
}
return nil
}
原始 HTTP
不使用客户端库。
GET /mirror/v1/contacts/harold HTTP/1.1
Authorization: Bearer auth token
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-08-23。
[null,null,["最后更新时间 (UTC):2024-08-23。"],[[["\u003cp\u003eRetrieves a single contact using their unique ID.\u003c/p\u003e\n"],["\u003cp\u003eRequires authorization with the \u003ccode\u003ehttps://www.googleapis.com/auth/glass.timeline\u003c/code\u003e scope.\u003c/p\u003e\n"],["\u003cp\u003eReturns a \u003ccode\u003eContacts\u003c/code\u003e resource with details like displayName and imageUrls upon successful execution.\u003c/p\u003e\n"],["\u003cp\u003eProvides code examples in various programming languages, including Java, .NET, PHP, Python, Ruby, and Go, demonstrating how to retrieve a contact.\u003c/p\u003e\n"]]],[],null,["# Contacts: get\n\n**Requires [authorization](#auth)**\n\nGets a single contact by ID.\n[See an example](#examples).\n\nRequest\n-------\n\n### HTTP request\n\n```\nGET https://www.googleapis.com/mirror/v1/contacts/id\n```\n\n### Parameters\n\n| Parameter name | Value | Description |\n|----------------|----------|------------------------|\n| **Path parameters** |||\n| `id` | `string` | The ID of the contact. |\n\n### Authorization\n\nThis request requires authorization with the following scope ([read more about authentication and authorization](/glass/authorization)).\n\n| Scope |\n|--------------------------------------------------|\n| `https://www.googleapis.com/auth/glass.timeline` |\n\n### Request body\n\nDo not supply a request body with this method.\n\nResponse\n--------\n\nIf successful, this method returns a [Contacts resource](/glass/v1/reference/contacts#resource) in the response body.\n\nExamples\n--------\n\n**Note:** The code examples available for this method do not represent all supported programming languages (see the [client libraries page](/glass/tools-downloads/client-libraries) for a list of supported languages). \n\n### Java\n\nUses the [Java client library](/glass/tools-downloads/client-libraries). \n\n```java\nimport com.google.api.services.mirror.Mirror;\nimport com.google.api.services.mirror.model.Contact;\n\nimport java.io.IOException;\n\npublic class MyClass {\n // ...\n\n /**\n * Print information for a contact.\n * \n * @param service Authorized Mirror service.\n * @param contactId ID of the Contact to print information for.\n */\n public static void printContact(Mirror service, String contactId) {\n try {\n Contact contact = service.contacts().get(contactId).execute();\n\n System.out.println(\"Contact displayName: \" + contact.getDisplayName());\n if (contact.getImageUrls() != null) {\n for (String imageUrl : contact.getImagesUrls()) {\n System.out.println(\"Contact imageUrl: \" + imageUrl);\n }\n }\n } catch (IOException e) {\n System.err.println(\"An error occurred: \" + e);\n }\n }\n\n // ...\n}\n```\n\n### .NET\n\nUses the [.NET client library](/glass/tools-downloads/client-libraries). \n\n```css+lasso\nusing System;\n\nusing Google.Apis.Mirror.v1;\nusing Google.Apis.Mirror.v1.Data;\n\npublic class MyClass {\n // ...\n\n /// \u003csummary\u003e\n /// Print information for a contact.\n /// \u003c/summary\u003e\n /// \u003cparam name='service'\u003eAuthorized Mirror service\u003c/param\u003e\n /// \u003cparam name='contactId'\u003e\n /// ID of the Contact to print information for.\n /// \u003c/param\u003e\n public static void PrintContact(MirrorService service,\n String contactId) {\n try {\n Contact contact = service.Contacts.Get(contactId).Fetch();\n\n Console.WriteLine(\n \"Contact displayName: \" + contact.DisplayName);\n if (contact.ImageUrls != null) {\n foreach (String imageUrl in contact.ImageUrls) {\n Console.WriteLine(\"Contact imageUrl: \" + imageUrl);\n }\n }\n } catch (Exception e) {\n Console.WriteLine(\"An error occurred: \" + e.Message);\n }\n }\n\n // ...\n}\n```\n\n### PHP\n\nUses the [PHP client library](/glass/tools-downloads/client-libraries). \n\n```php\n/*\n * Print information for a contact.\n *\n * @param Google_MirrorService $service Authorized Mirror service.\n * @param string $contactId ID of the Contact to print information for.\n */\nfunction printContact($service, $contactId) {\n try {\n $contact = $service-\u003econtacts-\u003eget($contactId);\n\n print 'Contact displayName: ' . $contact-\u003egetDisplayName();\n if ($contact-\u003egetImageUrls() != null) {\n foreach ($contact-\u003egetImageUrls() as $imageUrl) {\n print 'Contact imageUrl: ' . $imageUrl;\n }\n }\n } catch (Exception $e) {\n print 'An error occurred: ' . $e-\u003egetMessage();\n }\n}\n```\n\n### Python\n\nUses the [Python client library](/glass/tools-downloads/client-libraries). \n\n```python\nfrom apiclient import errors\n# ...\n\ndef print_contact(service, contact_id):\n \"\"\"Print information for a contact.\n\n Args:\n service: Authorized Mirror service.\n contact_id: ID of the Contact to print information for.\n \"\"\"\n try:\n contact = service.contacts().get(id= contact_id).execute()\n print 'Contact displayName: %s' % contact.get('displayName')\n for image_url in contact.get('imageUrls', []):\n print 'Contact imageUrl: %s' % image_url\n except errors.HttpError, error:\n print 'An error occurred: %s' % error\n```\n\n### Ruby\n\nUses the [Ruby client library](/glass/tools-downloads/client-libraries). \n\n```ruby\n##\n# Print information for a contact.\n#\n# @param [Google::APIClient] client\n# Authorized client instance.\n# @param [String] contact_id\n# ID of the contact to print information for.\n# @return nil\ndef print_contact(client, contact_id)\n mirror = client.discovered_api('mirror', 'v1')\n result = client.execute(\n :api_method =\u003e mirror.contacts.get,\n :parameters =\u003e { 'id' =\u003e contact_id })\n if result.success?\n contact = result.data\n puts \"Contact displayName: #{contact.displayName}\"\n contact.image_urls.each do |image_url|\n puts \"Contact imageUrl: #{image_url}\"\n end\n else\n puts \"An error occurred: #{result.data['error']['message']}\"\n end\nend\n```\n\n### Go\n\nUses the [Go client library](/glass/tools-downloads/client-libraries). \n\n```go\nimport (\n \"code.google.com/p/google-api-go-client/mirror/v1\"\n \"fmt\"\n)\n\n// PrintContact prints information for a contact.\nfunc PrintContact(g *mirror.Service, contactId string) error {\n s, err := g.Contacts.Get(contactId).Do()\n if err != nil {\n fmt.Printf(\"An error occurred: %v\\n\", err)\n return err\n }\n fmt.Printf(\"Contact displayName: %s\\n\", s.DisplayName)\n for _, i := range s.ImageUrls {\n fmt.Printf(\"Contact imageUrl: %s\\n\", i)\n }\n return nil\n}\n```\n\n### Raw HTTP\n\nDoes not use a client library. \n\n```http\nGET /mirror/v1/contacts/harold HTTP/1.1\nAuthorization: Bearer auth token\n```"]]