rapidwebltd / php-google-people-api

👥 This package provides a user friendly way of interacting with Google Contacts via the Google People API.
GNU Lesser General Public License v3.0
100 stars 39 forks source link

Memberships #11

Open priitn1 opened 6 years ago

priitn1 commented 6 years ago

The whole Google API is a bit confusing in naming their properties. What I would like to do is after adding a new Contact it would also have a predefined "Label" to it on the Google Contacts page.

What I gather is that the "Labels" are defined under the Contacts object memberships[] value? People API says it's read-only and it's also not under the UPDATE_PERSON_FIELDS constant.

I found something called contactGroups but im not sure it's the right resource?

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/63128242-memberships?utm_campaign=plugin&utm_content=tracker%2F87779827&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F87779827&utm_medium=issues&utm_source=github).
paugnu commented 5 years ago

Hi @priitn1, did you manage to get how to do it?

Monsieux commented 5 years ago

I think I have a clue, but I don't have the skills to retreive data from it, because it is a nested array.

{
  "resourceName": "people/c############",
  "etag": "%EgMBNy4aDAECAwQFBgcICQoLDCI",
  "memberships": [
    {
      "metadata": {
        "source": {
          "type": "CONTACT",
          "id": "################"
        }
      },
      "contactGroupMembership": {
        "contactGroupId": "54c066"
      }
    },
    {
      "metadata": {
        "source": {
          "type": "CONTACT",
          "id": "################"
        }
      },
      "contactGroupMembership": {
        "contactGroupId": "7a2810"
      }
    },
    {
      "metadata": {
        "source": {
          "type": "CONTACT",
          "id": "2bb4fe39"
        }
      },
      "contactGroupMembership": {
        "contactGroupId": "myContacts"
      }
    }
  ]
}

Next the PHP code as described in the wiki:

$contact = $people->get('people/c############');
    echo $contact->memberships[0]->contactGroupId;

Because it is a nested array, I could not managed to echo (contactGroupId) the data. I need this solution too, hope we can find it.

VivianaBruno commented 3 years ago

Hi! A bit late but you can get the groupId like this:

$contact->memberships[0]->contactGroupMembership->contactGroupId

luisdatec commented 3 years ago

Is this work for you guys ? $contact->memberships[0]->contactGroupMembership->contactGroupId