Google Plus

The Google+ API is the programming interface to Google+. You can use the API to integrate your app or website with Google+. This enables users to connect with each other for maximum engagement using Google+ features from within your application. To plus analytics services you need to grab an access token by authenticating first. The analytics scope when generating a URL can be passed by simply setting 'plus' to getLoginURL(). Figure 1 shows how we can obtain an access token for Google+.

Figure 1. Authentication
session_start();

$auth = eden('google')->auth('[CLIENT_ID]', '[CLIENT_SECRET]', 'http://yourwebsite.com/auth', '[API_KEY]');

//if no code and no session
if(!isset($_GET['code']) && !isset($_SESSION['token'])) {
    //redirect to login
    $login = $auth->getLoginUrl('plus');
    header('Location: '.$login);
    exit;
}

//Code is returned back from google
if(isset($_GET['code'])) {
    //save it to session
	$access = $auth->getAccess($_GET['code']);
    $_SESSION['token'] = $access['access_token'];
	
}

When we have our token we can then access the different service levels of Google+.

Figure 2. Instantiate Google Plus
$plus = eden('google')->plus($_SESSION['token']);
Figure 3. Plus Methods
Method Arguments Returns Description
$plus->activity(); none Eden_Google_Plus_Activity Factory method for Eden_Google_Plus_Activity Class
$plus->comment(); none Eden_Google_Plus_Activity Factory method for Eden_Google_Plus_Activity Class
$plus->people(); none Eden_Google_Plus_People Factory method for Eden_Google_Plus_People Class

Google Plus Activity

An activity is a note that a user posts to their stream. Activity methods enable your application to list a collection of activities, get an activity and search through activities.

Figure 1c. Instantiate Google Plus Acitivity
$activity = $plus->activity();
Figure 4. Usage: Get Activity
$activity
	->setMaxResults(20)			//optional
	->setPageToken($pageToken)	//optional 
	->getList();
Figure 5. Comment Methods
Method Arguments Returns Description
$activity->setPageToken($pageToken);
  1. string
array Set page token
$activity->setMaxResults($maxResults);
  1. integer
Eden_Google_Plus_Activity The maximum number of people to include in the response, used for paging.
$activity->orderByBest(); none Eden_Google_Plus_Activity Sort activities by relevance to the user, most relevant first.
$activity->orderByRecent(); none Eden_Google_Plus_Activity Sort activities by published date, most recent first.
$activity->getList($userId = self::ME);
  1. string
array Get activity list of user
$activity->getSpecific($activityId);
  1. string
array Get an activity
$activity->search($queryString);
  1. string|integer
array Search public activities

Google Plus Comment

A comment is a reply to an activity. Comment methods enable your application to list a collection of comments and get a comment.

$comment = $plus->comment();
Figure 6. Comment Methods
Method Arguments Returns Description
$comment->setPageToken($pageToken);
  1. string
Eden_Google_Plus_Comment The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of "nextPageToken" from the previous response.
$comment->setMaxResults($maxResults);
  1. integer
Eden_Google_Plus_Comment The maximum number of people to include in the response, used for paging.
$comment->descendingOrder();
  1. string
array Sort newest comments first.
$comment->getList($activityId);
  1. string
array List all of the comments for an activity.
$comment->getSpecific($commentId);
  1. string
array Get a comment

Google Plus People

People is a list of person resources, each of which represents a Google+ user. People methods enable your application to get a person's profile, search through profiles, and list all of the people who have +1'd or reshared a particular activity. Each person has an uniquely identifying ID.

$people = $plus->people();
Figure 7. Usage: Get User information
$people->getUserInfo();
Figure 8. People Methods
Method Arguments Returns Description
$people->setPageToken($pageToken);
  1. string
Eden_Google_Plus_People The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of "nextPageToken" from the previous response.
$people->setMaxResults($maxResults);
  1. integer
Eden_Google_Plus_People The maximum number of people to include in the response, used for paging.
$people->getUserInfo($userId = self::ME);
  1. string
array Returns user info
$people->search($queryString);
  1. string|integer
  2. - Full text search of public text in all profiles.
array Returns people that matches the queryString
$people->getActivityList($activityId, $collection);
  1. string
  2. string
array List all of the people in the specified collection for a particular activity

© 2012 Openovate Labs. All rights reserved.