Contacts: list
Stay organized with collections
Save and categorize content based on your preferences.
Requires authorization
Retrieves a list of contacts for the authenticated user.
See an example.
Request
HTTP request
GET https://www.googleapis.com/mirror/v1/contacts
Authorization
This request requires authorization with the following scope (read more about authentication and authorization).
Scope |
https://www.googleapis.com/auth/glass.timeline |
Request body
Do not supply a request body with this method.
Response
If successful, this method returns a response body with the following structure:
{
"kind": "mirror#contacts",
"items": [
contacts Resource
]
}
Property name |
Value |
Description |
Notes |
kind |
string |
The type of resource. This is always mirror#contacts . |
|
items[] |
list |
Contact list. |
|
Examples
Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).
Java
Uses the Java client library.
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
Uses the .NET client library.
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
Uses the PHP client library.
/**
* 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
Uses the Python client library.
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
Uses the Ruby client library.
##
# 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
Uses the Go client library.
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
}
Raw HTTP
Does not use a client library.
GET /mirror/v1/contacts HTTP/1.1
Authorization: Bearer auth token
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\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```"]]