tpih Posted September 18, 2011 Share Posted September 18, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/ Share on other sites More sharing options...
voip03 Posted September 18, 2011 Share Posted September 18, 2011 Could you post the full code? Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270330 Share on other sites More sharing options...
tpih Posted September 18, 2011 Author Share Posted September 18, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270342 Share on other sites More sharing options...
voip03 Posted September 18, 2011 Share Posted September 18, 2011 What you are trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270347 Share on other sites More sharing options...
tpih Posted September 18, 2011 Author Share Posted September 18, 2011 get it to print what the string in "emails[].value" is but every way I have tried hasn't worked Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270348 Share on other sites More sharing options...
creata.physics Posted September 18, 2011 Share Posted September 18, 2011 Can you do: var_dump($me); underneath: $activities = $plus->activities->listActivities('me', 'public', $optParams); Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270349 Share on other sites More sharing options...
tpih Posted September 18, 2011 Author Share Posted September 18, 2011 It did nothing. Should it have done something? Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270362 Share on other sites More sharing options...
creata.physics Posted September 18, 2011 Share Posted September 18, 2011 Yeah, it should have outputted at least NULL somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270369 Share on other sites More sharing options...
tpih Posted September 18, 2011 Author Share Posted September 18, 2011 tried it in another place and got NULL. Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270371 Share on other sites More sharing options...
creata.physics Posted September 18, 2011 Share Posted September 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270372 Share on other sites More sharing options...
tpih Posted September 18, 2011 Author Share Posted September 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270378 Share on other sites More sharing options...
tpih Posted September 18, 2011 Author Share Posted September 18, 2011 Also thank you very much creata.physics var_dump is now working. Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270379 Share on other sites More sharing options...
creata.physics Posted September 18, 2011 Share Posted September 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270380 Share on other sites More sharing options...
tpih Posted September 18, 2011 Author Share Posted September 18, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270383 Share on other sites More sharing options...
creata.physics Posted September 18, 2011 Share Posted September 18, 2011 Can you please give me a link to reference to this api so I can check out the documentation? Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270392 Share on other sites More sharing options...
tpih Posted September 18, 2011 Author Share Posted September 18, 2011 https://developers.google.com/+/api/latest/people Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270455 Share on other sites More sharing options...
creata.physics Posted September 18, 2011 Share Posted September 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270494 Share on other sites More sharing options...
tpih Posted September 19, 2011 Author Share Posted September 19, 2011 Thanks a lot for your help mate Quote Link to comment https://forums.phpfreaks.com/topic/247356-google-api-help/#findComment-1270545 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.