Google People API互联网通话字段设置问题:无对应属性且创建不支持
Great question! I’ve dealt with this exact confusion before when working with the Google People API. The "Internet call" field you see in Google Contacts isn’t listed as a dedicated, named property in the API documentation, but it maps directly to the imClients resource in the API schema. Here’s how to work with it:
Key Mapping Explanation
Google Contacts groups all internet-based call/messaging accounts (like Skype, WhatsApp, Signal, or custom services) under the imClients array in the People API. Each entry in this array represents one internet call/IM account, with core properties:
type: A predefined enum value (likeskype,hangouts,qq) orcustomfor services not on the predefined list.value: The actual account ID/handle/number for the service.- (Optional)
label: Required only when usingtype: "custom"; this sets the display name for the internet call service in Google Contacts.
Example: Creating a Contact with an Internet Call Field
Here’s a Python code snippet using the Google API client library to create a contact with a Skype account and a custom WhatsApp internet call entry:
from googleapiclient.discovery import build # Assume you've already handled authentication and have valid credentials people_service = build('people', 'v1', credentials=credentials) # Define the contact body with internet call entries contact_payload = { "names": [ { "givenName": "Jerald", "familyName": "Lawrence" } ], "imClients": [ # Predefined Skype entry { "type": "skype", "value": "jerald.lawrence.skype" }, # Custom WhatsApp internet call entry { "type": "custom", "label": "WhatsApp", "value": "+12345678901" } ] } # Create the contact created_contact = people_service.people().createContact(body=contact_payload).execute() print(f"Success! Contact created with resource name: {created_contact['resourceName']}")
Updating an Existing Contact's Internet Call Field
If you need to add or modify this field for an existing contact, use the updateContact method and specify updatePersonFields=imClients to target only this field:
# Replace with your contact's resource name contact_resource_name = "people/c123456789" update_payload = { "imClients": [ { "type": "custom", "label": "Signal", "value": "+0987654321" } ] } # Update the contact updated_contact = people_service.people().updateContact( resourceName=contact_resource_name, body=update_payload, updatePersonFields="imClients" ).execute()
Notes
- Predefined
imClientstypes include common services likeskype,hangouts,qq, and more—using these ensures consistent display in Google Contacts. - When using the
customtype, thelabelyou set will appear as the service name next to the internet call entry in Contacts, exactly matching the field you’re trying to populate.
内容的提问来源于stack exchange,提问作者Jerald Lawrence

