Jump to content

Recommended Posts

It is pretty much the sample one that google give you.

 

<?php

/*

* Copyright 2011 Google Inc.

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

*    http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

require_once 'google-api-php-client/src/apiClient.php';

require_once 'google-api-php-client/src/contrib/apiPlusService.php';

 

session_start();

 

$client = new apiClient();

$client->setApplicationName("Google+ PHP Starter Application");

// Visit https://code.google.com/apis/console to generate your

// oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.

// $client->setClientId('insert_your_oauth2_client_id');

// $client->setClientSecret('insert_your_oauth2_client_secret');

// $client->setRedirectUri('insert_your_oauth2_redirect_uri');

// $client->setDeveloperKey('insert_your_developer_key');

$client->setScopes(array('https://www.googleapis.com/auth/plus.me'));

$plus = new apiPlusService($client);

 

if (isset($_REQUEST['logout'])) {

  unset($_SESSION['access_token']);

}

 

if (isset($_GET['code'])) {

  $client->authenticate();

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

  header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);

}

 

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

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

}

 

if ($client->getAccessToken()) {

  $me = $plus->people->get('me');

 

  $optParams = array('maxResults' => 100);

  $activities = $plus->activities->listActivities('me', 'public', $optParams);

 

  // The access token may have been updated lazily.

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

} else {

  $authUrl = $client->createAuthUrl();

}

?>

<!doctype html>

<html>

<head><link rel='stylesheet' href='style.css' /></head>

<body>

<header><h1>Google+ Sample App</h1></header>

<div class="box">

<?php if(isset($me) && isset($activities)): ?>

<?php

echo "Display Name: {$me['displayName']}\n";

echo "URL: {$me['url']}\n";

echo "Profile Image: {$me['image']['url']}\n";

endif;

?>

</div>

</body>

</html>

 

Link to comment
https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270342
Share on other sites

Okay so this code:

if ($client->getAccessToken()) {
  $me = $plus->people->get('me');

 

Is not working. Right Below

if ($client->getAccessToken()) {

 

Please add die('test'); and tell me if you see test on a white page.

 

I'm asking because I need to know if $client is being set properly, and getAccessToken() function is returning as true.

 

Actually, scratch that, since you said NULL didn't appear there, it's obvious the if statement isn't passing so the code inside of it will not work.

 

The issue is with $client, I don't think you are setting the necessary information properly.

 

// $client->setClientId('insert_your_oauth2_client_id');

// $client->setClientSecret('insert_your_oauth2_client_secret');

// $client->setRedirectUri('insert_your_oauth2_redirect_uri');

// $client->setDeveloperKey('insert_your_developer_key');

 

You need to add those without the two backslashes ( // ) and populate those functions with your proper information.

Link to comment
https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270372
Share on other sites

It is returning data.

 

array( { ["kind"]=> string(11) "plus#person" ["id"]=> string(21) "101577478827733*****" ["displayName"]=> string(12) "Tyler *****" ["gender"]=> string(4) "male" ["url"]=> string(45) "https://plus.google.com/101577478827********" ["image"]=> array(1) { ["url"]=> string(92) "https://lh4.googleusercontent.com/-90ZR6GIMonM/AAAAAAAAAAI/AAAAAAAAACQ/6_nC11C3d_s/photo.jpg" } ["urls"]=> array(2) { [0]=> array(2) { ["value"]=> string(45) "https://plus.google.com/101577478********" ["type"]=> string(7) "profile" } [1]=> array(2) { ["value"]=> string(63) "https://www.googleapis.com/plus/v1/people/1015774788277*******" ["type"]=> string(4) "json" } } ["placesLived"]=> array(1) { [0]=> array(1) { ["value"]=> string(22) "**************" } } }

 

As you can see there is NO email. Any idea on why no email would be appearing?

Link to comment
https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270383
Share on other sites

Okay, so I've messed with the website a bit (havent tried the actual api yet) and this is where I stumped to:

https://developers.google.com/+/api/latest/people/get#examples

 

Now, you can put "me" in the first box, and put the fields you want to load in the second.

 

What I did was checked all fields and checked the output, there was no email populated.  What I'm thinking is this may be an issue with google's api, since emails are meant to load, but don't.

 

I would start a discussion here: http://groups.google.com/group/google-plus-developers/topics

 

They are more familiar with the api, they may be able to help you a bit more than I can.

Link to comment
https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270494
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.