Git Product home page Git Product logo

php-google-people-api's Introduction

๐Ÿ‘ฅ PHP Google People API

This package provides a user friendly way of interacting with Google Contacts via the Google People API.

Installation

PHP Google People API can be easily installed using Composer. Just run the following command from the root of your project.

composer require rapidwebltd/php-google-people-api

If you have never used the Composer dependency manager before, head to the Composer website for more information on how to get started.

Setup

To use this package, you need to authenticate with Google via OAuth 2. Thankfully, this is made easy by the PHP Google OAuth 2 Handler package.

You can run its guided setup script with the following command.

php vendor/rapidwebltd/php-google-oauth-2-handler/src/setup.php

This will guide you through the process of setting up a project, and logging into to the Google account that you wish to manage contacts for. When asked which scopes you require access to, enter the following.

https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/contacts
https://www.googleapis.com/auth/contacts.readonly

When complete, you will have to code you need to create a GoogleOAuth2Handler object for this Google account.

You can then create a GooglePeople object, as follows.

$people = new GooglePeople($googleOAuth2Handler);

Usage

Retrieve all contacts

// Retrieval all contacts
foreach($people->all() as $contact) {
    echo $contact->resourceName.' - ';
    if ($contact->names) {
        echo $contact->names[0]->displayName;
    }
    echo PHP_EOL;
}

Retrieve a single contact

// Retrieve single contact (by resource name)
$contact = $people->get('people/c8055020007701654287');

Create a new contact

// Create new contact
$contact = new Contact($people);
$contact->names[0] = new stdClass;
$contact->names[0]->givenName = 'Testy';
$contact->names[0]->familyName = 'McTest Test';
$contact->save();

Update a contact

// Update contact
$contact->names[0]->familyName = 'McTest';
$contact->save();

Delete a contact

// Delete contact
$contact->delete();

php-google-people-api's People

Contributors

divineomega avatar juniyadi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.