Jump to content

Archived

This topic is now archived and is closed to further replies.

tpih

Google + Api Help

Recommended Posts

On googles developers web site it states "emails[].value" to get the value of a users email. I tried $me['emails']['value'] which some people told me to use but it didn't work. Any ideas on how to code it so it works?

Share this post


Link to post
Share on other sites

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>

 

Share this post


Link to post
Share on other sites

get it to print what the string in "emails[].value" is but every way I have tried hasn't worked

Share this post


Link to post
Share on other sites

Can you do:

var_dump($me);

 

underneath:

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

I think I must have accidently uploaded the wrong file at one point because I am damn sure they were set before and they weren't just before I changed them.

Share this post


Link to post
Share on other sites

So we now have data populated for $me ?

 

If so, can I please see the details so I can inform you on how to call the email field.

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×
×
  • 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.