Google API PHP Client - Contacts Service

phpapicontactsgoogleoutlookservicesv3client

Last Update : 2023-09-22 UTC 12:13:12 PM

Answers of > Google API PHP Client - Contacts Service

I had to work with this recently and after w3coded contacts client finding the lack of a Contacts service in the w3coded contacts client official PHP Google Client, I created a (MIT w3coded contacts client licensed) PHP library for the Google Contacts w3coded contacts client API.,I've created a new package to manage Google w3coded contacts client Contacts based on the newer Google People API. w3coded contacts client If you're started a new project, I'd recommend w3coded contacts client you use this package instead of the one w3coded contacts client mentioned in my original post below.,EDIT: My w3coded contacts client progress so far. The last lines fails with w3coded contacts client response from Google: 401. There was an error in w3coded contacts client your request. - I guess that is because of lack w3coded contacts client of permission (I didn't ask for Contacts w3coded contacts client permission). But how do I do this, without the w3coded contacts client "Google_ContactsService.php"? I am lost. See w3coded contacts client code:,Unfortunately the contacts API is one of w3coded contacts client the older GData ones, while this library is w3coded contacts client for the newer APIs. You can use the OAuth part w3coded contacts client of the library to request the scope w3coded contacts client (https://www.googleapis.com/auth/contacts.readonly), w3coded contacts client and use the token to make the request, but w3coded contacts client you'll have to parse the data manually. Zend w3coded contacts client Framework does have the Zend_Gdata classes that w3coded contacts client might make reading the results a bit w3coded contacts client easier!

One of the aims is to really simplify some of the process involved. So to answer your question, after setting up the library, the following code is all that is needed to retrieve contacts.

require_once '../../../vendor/autoload.php';
use rapidweb\googlecontacts\factories\ContactFactory;
$contacts = ContactFactory::getAll();
if (count($contacts)) {
    echo 'Test retrieved '.count($contacts).' contacts.';
} else {
    echo 'No contacts retrieved!';
}

The library needs a little work, but works well for basic contact retrieval, creation and updating. It can also be installed via composer if needed. Just add the following to your composer.json and run composer update.

{
  "require": {
       "rapidwebltd/php-google-contacts-v3-api": "dev-master"
   }
}

oauth2callback.php (note that the full path to this has to be listed on the APIs & Auth/Credentials section of your Developer Console or your calls will fail):

<?php

set_include_path(get_include_path() . PATH_SEPARATOR . '/data/www/unity/html/lib');  # The path where I git got google-api-php-client
require_once 'google-api-php-client/src/Google/autoload.php';

$APPPATH = "/Applications/GFContacts";

session_start();

$client = new Google_Client();
$client->setAuthConfigFile('accountinfo.json'); # JSON config file downloaded from the credentials page of my project https://console.developers.google.com/project
$client->setRedirectUri('https://' . $_SERVER['HTTP_HOST'] . $APPPATH . '/oauth2callback.php');
$client->addScope("https://www.googleapis.com/auth/contacts.readonly");

if (! isset($_GET['code'])) {
  $auth_url = $client->createAuthUrl();
  header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else {
  $client->authenticate($_GET['code']);
  $_SESSION['access_token'] = $client->getAccessToken();
  $redirect_uri = 'https://' . $_SERVER['HTTP_HOST'] . $APPPATH;
  header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}

?>

And then index.php:

<?php

set_include_path(get_include_path() . PATH_SEPARATOR . '/data/www/unity/html/lib');  # The path where I git got google-api-php-client

require_once 'google-api-php-client/src/Google/autoload.php';
$APPPATH = "/Applications/GFContacts"; # relative path from server root

session_start();

$client = new Google_Client();
$client->setAuthConfigFile('accountinfo.json'); # JSON config file downloaded from the credentials page of my project https://console.developers.google.com/project
$client->addScope("https://www.googleapis.com/auth/contacts.readonly");

# Allow a param 'logout' to remove the access token - sometimes doing this helps debug issues
if (isset($_REQUEST['logout'])) {
    unset($_SESSION['access_token']);
    $client->revokeToken();

    print "You're logged out of Google";

    exit;
}

if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {

    $access_token = json_decode($_SESSION['access_token'])->access_token;

    $client->setAccessToken($_SESSION['access_token']);

    $req = new Google_Http_Request("https://www.google.com/m8/feeds/contacts/default/full");
    $val = $client->getAuth()->authenticatedRequest($req);

    // The contacts api only returns XML responses.
    $response = json_encode(simplexml_load_string($val->getResponseBody()));
    print "<pre>" . print_r(json_decode($response, true), true) . "</pre>"; 

} else {
    $redirect_uri = 'https://' . $_SERVER['HTTP_HOST'] . $APPPATH . '/oauth2callback.php';
    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}

?>

Current topics : Google API PHP Client - Contacts Service

Newly Added Questions

Similar Questions

Questions :

How To Group Array Key Value

Last Update : 2023-09-22 UTC 12:39:51 PM

Questions :

PhpStorm Warning For React Attributes In Jsx File With SCSS File

Last Update : 2023-09-22 UTC 12:39:38 PM

Questions :

Why Is The File Not Showing Up In Request.files And In Request.forms Instead?

Last Update : 2023-09-22 UTC 12:39:25 PM

Questions :

Proxying Assets From React App Directory In Slim Framework?

Last Update : 2023-09-22 UTC 12:39:12 PM

Questions :

Laravel 5.4 Can't Run “php Artisan Preset React” Comand

Last Update : 2023-09-22 UTC 12:39:03 PM

Questions :

How To Update Session Values Without Signing Out?

Last Update : 2023-09-22 UTC 12:38:58 PM

Questions :

Array Is Not Visible

Last Update : 2023-09-22 UTC 12:38:50 PM

Questions :

React Routing For Login Using Symfony

Last Update : 2023-09-22 UTC 12:38:39 PM

Questions :

Sanctum With React SPA Returning 419 Page Expired

Last Update : 2023-09-22 UTC 12:38:30 PM

Questions :

How Do I Import An Input String Into Another Page

Last Update : 2023-09-22 UTC 12:38:18 PM

Top
© 2023 W3CODED - All Rights Reserved.