Git Product home page Git Product logo

google-api-client-codeigniter-spark's Introduction

Google API Client

The summary description of this spark is simple: this is simply version 0.6.0 of the Google distributed PHP API Client (which supports Google's API version 3), without a single code change made to it, made available to the Sparks repository.

The Google API Client is used to interact with a plethora of Google web services:

  • AdSense
  • Affiliate Network
  • Analytics
  • Apps
  • Books
  • Calendar
  • Contacts
  • Latitude
  • Page Speed
  • Plus
  • Shopping
  • Tasks
  • Translate
  • URL Shortener
  • User Info
  • Web Fonts

All of the included documentation is included within this Spark directory (including Google's README file, included at the bottom of this document, LICENSE, NOTICE, examples, etc.)

Why Didn't You Port Anything To Codeigniter-ese?

Google has done a great job making their API easy to use, and they have provided a number of examples that users can simply copy and paste into their code. Since this is such a convenience for novice users or users unfamiliar with the Google API, this capability remains, so copy and paste away?

What Changes Are There With This Spark Compared to The Google Distributed Code?

None, but for your convenience we have included some example code which makes referencing the libraries included in this repository by name a little easier. Instead of doing:

<?php
require_once '../../src/apiClient.php';
?>

since conceptualizing these paths might be a little tricky within CodeIgniter, you can do:

<?php
require_once SPARKPATH . "GoogleAPIClient/0.6.0/src/apiClient.php";
?>

How Do I Load This Spark?

Normally this would be:

<?php
$this->load->spark('GoogleAPIClient/0.6.0');
?>

but this doesn't actually do anything since there are no CodeIgniter-esque config files, helpers, or libraries within this Spark. Just follow the example code (some included below) to init this Spark.

One note though, because you'll probably want to speak to Google within a CodeIgniter controller, you'll need to make available the variables defined in the included configuration file (see below) in your controller, which you can do as such (include this line before you start speaking to Google).

<?php
global $apiConfig;
?>

So What's the Point Of This Stupid Thing?

Pretty much just:

  • The ability to install and update this via the Sparks system
  • The ability to use SPARKPATH to integrate this a little easier within your CodeIgniter projects
  • The ability to keep this code isolated from the rest of your project, the Sparks way

Example Code/How To

Just as you would with using this API outside of CodeIgniter/Sparks:

  1. Get yourself a Google Account
  2. Register your project with Google, and obtain an oAuth Client ID and Client Secret via the "API Access" of your Google API Console. Decide what URL you want your users to be redirected to after successful oAuth authorization/authentication and enter that here as well. Take note of these three values.
  3. Enter these three values into the included src/config.php file where prompted.

You can now access these Google services via the included example code, included here (an example that fetches a list of calendars within your account) with the aforementioned path alterations for your convenience:

<?php
global $apiConfig;

require_once SPARKPATH . "GoogleAPIClient/0.6.0/src/apiClient.php";
require_once SPARKPATH . "GoogleAPIClient/0.6.0/src/contrib/apiCalendarService.php";

// init API
$apiClient = new apiClient();
$apiClient->setApplicationName("Google Calendar PHP Starter Application");
$apiClient->setUseObjects(true);

// init Google Calendar
$cal = new apiCalendarService($apiClient);

// authenticate/authorize user
if (isset($_SESSION['oauth_access_token'])) {
	$apiClient->setAccessToken($_SESSION['oauth_access_token']);
} else {
	$token = $apiClient->authenticate();
	$_SESSION['oauth_access_token'] = $token;
}

// list your calendars
if ($apiClient->getAccessToken()) {
	$calList = $cal->calendarList->listCalendarList();
	print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";
	$_SESSION['token'] = $apiClient->getAccessToken();
} else {
	$authUrl = $apiClient->createAuthUrl();
	print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
?>

The original Google README file is included below:

Google APIs Client Library for PHP

Description

The Google API Client Library enables you to work with Google APIs such as Buzz, Moderator, Tasks, or Latitude on your server.

Requirements:

Project page:

http://code.google.com/p/google-api-php-client

OAuth 2 instructions:

http://code.google.com/p/google-api-php-client/wiki/OAuth2

Report a defect or feature request here:

http://code.google.com/p/google-api-php-client/issues/entry

Subscribe to project updates in your feed reader:

http://code.google.com/feeds/p/google-api-php-client/updates/basic

Supported sample applications:

http://code.google.com/p/google-api-php-client/wiki/Samples

Basic Example

<?php
require_once 'path/to/src/apiClient.php';
require_once 'path/to/src/contrib/apiBooksService.php';

$client = new apiClient();
$service = new apiBooksService($client);

$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);

foreach ($results['items'] as $item) {
	print($item['volumeInfo']['title'] . '<br>');
}

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.