Contacts: list
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
需要授权
检索已验证用户的联系人列表。
查看示例。
请求
HTTP 请求
GET https://www.googleapis.com/mirror/v1/contacts
授权
此请求需要获得下列范围的授权(详细了解身份验证和授权)。
范围 |
https://www.googleapis.com/auth/glass.timeline |
请求正文
使用此方法时请勿提供请求正文。
响应
如果成功,此方法将返回采用以下结构的响应正文:
{
"kind": "mirror#contacts",
"items": [
contacts Resource
]
}
属性名称 |
值 |
说明 |
备注 |
kind |
string |
资源类型。始终为 mirror#contacts 。 |
|
items[] |
list |
联系人列表。 |
|
示例
注意:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。
Java
使用 Java 客户端库。
import com.google.api.services.mirror.Mirror;
import com.google.api.services.mirror.model.Contact;
import com.google.api.services.mirror.model.ContactsListResponse;
import java.io.IOException;
public class MyClass {
// ...
/**
* Print all contacts for the current user.
*
* @param service Authorized Mirror service.
*/
public void printAllContacts(Mirror service) {
try {
ContactsListResponse contacts = service.contacts().list().execute();
for (Contact contact : contacts.getItems()) {
System.out.println("Contact ID: " + contact.getId());
System.out.println(" > displayName: " + contact.getDisplayName());
if (contact.getImageUrls() != null) {
for (String imageUrl : contact.getImageUrls()) {
System.out.println(" > 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 all contacts for the current user.
/// </summary>
/// <param name='service'>Authorized Mirror service.</param>
public static void PrintAllContacts(MirrorService service) {
try {
ContactsListResponse contacts =
service.Contacts.List().Fetch();
foreach (Contact contact in contacts.Items) {
Console.WriteLine("Contact ID: " + contact.Id);
Console.WriteLine(" > displayName: " + contact.DisplayName);
if (contact.ImageUrls != null) {
foreach (String imageUrl in contact.ImageUrls) {
Console.WriteLine(" > imageUrl: " + imageUrl);
}
}
}
} catch (Exception e) {
Console.WriteLine("An error occurred: " + e.Message);
}
}
// ...
}
PHP
使用 PHP 客户端库。
/**
* Print all contacts for the current user.
*
* @param Google_MirrorService service Authorized Mirror service.
*/
function printAllContacts($service) {
try {
$contacts = $service->contacts->listContacts();
foreach ($contacts->getItems() as $contact) {
print 'Contact ID: ' . $contact->getId();
print ' > displayName: ' . $contact->getDisplayName();
if ($contact->getImageUrls() != null) {
foreach ($contact->getImageUrls() as $imageUrl) {
print ' > imageUrl: ' . $imageUrl;
}
}
}
} catch (Exception $e) {
print 'An error occurred: ' . $e->getMessage();
return null;
}
}
Python
使用 Python 客户端库。
from apiclient import errors
# ...
def print_all_contacts(service):
"""Print all contacts for the current user.
Args:
service: Authorized Mirror service.
"""
try:
contacts = service.contacts().list().execute()
for contact in contacts.get('items', []):
print 'Contact ID: %s' % contact.get('id')
print ' > displayName: %s' % contact.get('displayName')
for image_url in contact.get('imageUrls', []):
print ' > imageUrl: %s' % image_url
except errors.HttpError, error:
print 'An error occurred: %s' % error
Ruby
使用 Ruby 客户端库。
##
# Print all contacts for the current user.
#
# @param [Google::APIClient] client
# Authorized client instance.
# @return nil
def print_all_contacts(client)
mirror = client.discovered_api('mirror', 'v1')
result = client.execute(:api_method => mirror.contacts.list)
if result.success?
contacts = result.data
contacts.items.each do |contact|
puts "Contact ID: #{contact.id}"
puts " > displayName: #{contact.display_name}"
contact['imageUrls'].each do |image_url|
puts " > imageUrl: #{image_url}"
end
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"
)
// PrintAllContacts prints all contacts for the current user.
func PrintAllContacts(g *mirror.Service) error {
s, err := g.Contacts.List().Do()
if err != nil {
fmt.Printf("An error occurred: %v\n", err)
return err
}
for _, st := range s.Items {
fmt.Printf("Contact ID: %s\n", st.Id)
fmt.Printf(" > displayName: %s\n", st.DisplayName)
for _, i := range st.ImageUrls {
fmt.Printf(" > imageUrl: %s\n", i)
}
}
return nil
}
原始 HTTP
不使用客户端库。
GET /mirror/v1/contacts 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 list of contacts for the authenticated user using the \u003ccode\u003eGET https://www.googleapis.com/mirror/v1/contacts\u003c/code\u003e request.\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\u003eThe response includes a list of contacts, each with properties like ID, display name, and image URLs.\u003c/p\u003e\n"],["\u003cp\u003eProvides code examples in various programming languages (Java, .NET, PHP, Python, Ruby, and Go) demonstrating how to retrieve and display contact information.\u003c/p\u003e\n"]]],[],null,["# Contacts: list\n\n**Requires [authorization](#auth)**\n\nRetrieves a list of contacts for the authenticated user.\n[See an example](#examples).\n\nRequest\n-------\n\n### HTTP request\n\n```\nGET https://www.googleapis.com/mirror/v1/contacts\n```\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 response body with the following structure:\n\n```objective-c\n{\n \"kind\": \"mirror#contacts\",\n \"items\": [\n contacts Resource\n ]\n}\n```\n\n| Property name | Value | Description | Notes |\n|---------------|----------|---------------------------------------------------------|-------|\n| `kind` | `string` | The type of resource. This is always `mirror#contacts`. | |\n| `items[]` | `list` | Contact list. | |\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;\nimport com.google.api.services.mirror.model.ContactsListResponse;\n\nimport java.io.IOException;\n\npublic class MyClass {\n // ...\n\n /**\n * Print all contacts for the current user.\n * \n * @param service Authorized Mirror service.\n */\n public void printAllContacts(Mirror service) {\n try {\n ContactsListResponse contacts = service.contacts().list().execute();\n\n for (Contact contact : contacts.getItems()) {\n System.out.println(\"Contact ID: \" + contact.getId());\n System.out.println(\" \u003e displayName: \" + contact.getDisplayName());\n if (contact.getImageUrls() != null) {\n for (String imageUrl : contact.getImageUrls()) {\n System.out.println(\" \u003e imageUrl: \" + imageUrl);\n }\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 all contacts for the current user.\n /// \u003c/summary\u003e\n /// \u003cparam name='service'\u003eAuthorized Mirror service.\u003c/param\u003e\n public static void PrintAllContacts(MirrorService service) {\n try {\n ContactsListResponse contacts =\n service.Contacts.List().Fetch();\n\n foreach (Contact contact in contacts.Items) {\n Console.WriteLine(\"Contact ID: \" + contact.Id);\n Console.WriteLine(\" \u003e displayName: \" + contact.DisplayName);\n if (contact.ImageUrls != null) {\n foreach (String imageUrl in contact.ImageUrls) {\n Console.WriteLine(\" \u003e imageUrl: \" + imageUrl);\n }\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 all contacts for the current user.\n *\n * @param Google_MirrorService service Authorized Mirror service.\n */\nfunction printAllContacts($service) {\n try {\n $contacts = $service-\u003econtacts-\u003elistContacts();\n\n foreach ($contacts-\u003egetItems() as $contact) {\n print 'Contact ID: ' . $contact-\u003egetId();\n print ' \u003e displayName: ' . $contact-\u003egetDisplayName();\n if ($contact-\u003egetImageUrls() != null) {\n foreach ($contact-\u003egetImageUrls() as $imageUrl) {\n print ' \u003e imageUrl: ' . $imageUrl;\n }\n }\n }\n } catch (Exception $e) {\n print 'An error occurred: ' . $e-\u003egetMessage();\n return null;\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_all_contacts(service):\n \"\"\"Print all contacts for the current user.\n\n Args:\n service: Authorized Mirror service.\n \"\"\"\n try:\n contacts = service.contacts().list().execute()\n for contact in contacts.get('items', []):\n print 'Contact ID: %s' % contact.get('id')\n print ' \u003e displayName: %s' % contact.get('displayName')\n for image_url in contact.get('imageUrls', []):\n print ' \u003e 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 all contacts for the current user.\n#\n# @param [Google::APIClient] client\n# Authorized client instance.\n# @return nil\ndef print_all_contacts(client)\n mirror = client.discovered_api('mirror', 'v1')\n result = client.execute(:api_method =\u003e mirror.contacts.list)\n if result.success?\n contacts = result.data\n contacts.items.each do |contact|\n puts \"Contact ID: #{contact.id}\"\n puts \" \u003e displayName: #{contact.display_name}\"\n contact['imageUrls'].each do |image_url|\n puts \" \u003e imageUrl: #{image_url}\"\n end\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// PrintAllContacts prints all contacts for the current user.\nfunc PrintAllContacts(g *mirror.Service) error {\n s, err := g.Contacts.List().Do()\n if err != nil {\n fmt.Printf(\"An error occurred: %v\\n\", err)\n return err\n }\n for _, st := range s.Items {\n fmt.Printf(\"Contact ID: %s\\n\", st.Id)\n fmt.Printf(\" \u003e displayName: %s\\n\", st.DisplayName)\n for _, i := range st.ImageUrls {\n fmt.Printf(\" \u003e imageUrl: %s\\n\", i)\n }\n }\n return nil\n}\n```\n\n### Raw HTTP\n\nDoes not use a client library. \n\n```http\nGET /mirror/v1/contacts HTTP/1.1\nAuthorization: Bearer auth token\n```"]]