Get user gender and birthday through sign-in with Google and PHP - google-api

I need to get user gender and birthday through sign-in with Google with PHP.
These are my oauth settings in Google cloud (the ones like "people API" and "userinfo.gender" that are described in older posts are not available amongst the selectable ones, so I only have the defauld ones: nothing more as you can see):
This is the login page generated by Google (note that gender and birthday are missing)
This is the PHP code that generates the login url of the screenshot above:
if(!session_id()){
session_start();
}
// Include Google API client library
require_once (dirname(__FILE__).'/../third_party/google-api-php-client/vendor/autoload.php');
// Call Google API
$gClient = new Google_Client();
$gClient->setApplicationName('Login to *********');
$gClient->setClientId(GOOGLE_CLIENT_ID);
$gClient->setClientSecret(GOOGLE_CLIENT_SECRET);
$gClient->setRedirectUri(GOOGLE_REDIRECT_URL);
$gClient->addScope('email');
$gClient->addScope('profile');
$google_oauthV2 = new Google_Service_Oauth2($gClient);
// Get login url
$authUrl = $gClient->createAuthUrl();
// Render google login button
echo filter_var($authUrl, FILTER_SANITIZE_URL);
This is a sample response I get from Google after entering my account:
Google\Service\Oauth2\Userinfo Object ( [internal_gapi_mappings:protected] => Array ( [familyName] => family_name [givenName] => given_name [verifiedEmail] => verified_email ) [email] => contact#mysite.com [familyName] => Doe [gender] => [givenName] => John [hd] => mysite.com [id] => ******************** [link] => https://plus.google.com/********************* [locale] => en [name] => John Doe [picture] => https://lh3.googleusercontent.com/a/******************************** [verifiedEmail] => 1 [modelData:protected] => Array ( [verified_email] => 1 [given_name] => John [family_name] => Doe ) [processed:protected] => Array ( ) )
The app status is public: verification in progress, with a grant of 10K/day
This beig said, how do I get gender and birthday?

Related

How to call pass data to modal observer manually and fire observer

I am working on Laravel v4.2 project and I want to add a post into elasticsearch. But in my scenario post has multiple post media up to five and also post location and tag user users list. post, media and location and tags users entries have been done in the separate table due to foreign keys.
But my problem is that I put the modal observer on post modal and when I upload post then I only receive post modal information instead of the whole post including post, post media, post location and tag users list. So is then any best way to solve this issue that I receive all post data into the modal observer. One thing is considerable that tag users, post location and post media also has separate models and observer just put on post modal and the first entry is done in post table and after success then location, media and tag users below is my working code.
Post modal
if ($this->post = Post::create($updated_post_params)) {
//save post location , media
if ($this->savePostRelations($inputs, $data)) {
DB::commit();
} else if (connection_aborted()) {
throw new Exception('Connection abort!');
} else {
throw new Exception(Notifications::$error['multi_post_error']);
}
Observer
Post::observe(new PostObserver);
Current observer data received
Array
(
[post_type_id] => 1
[user_id] => 87
[text_content] =>
[client_ip_address] => 192.168.1.46
[local_db_path] => 18372547
[updated_at] => 2018-04-25 07:44:45
[created_at] => 2018-04-25 07:44:45
[id] => 11041871
)
Expected Observer data
Array
(
[post_type_id] => 1
[user_id] => 87
[text_content] =>
[client_ip_address] => 192.168.1.46
[local_db_path] => 18372547
[updated_at] => 2018-04-25 07:44:45
[created_at] => 2018-04-25 07:44:45
[id] => 11041871
[media] =>[
{
[id] => 12525
[file] => something.jpg
}
{
[id] => 12526
[file] => something.jpg
}
]
[location] =>[
{
[id] => 12525
[fs_location_id] => hhyf415214425hhsd
[location] => Banglore
}
]
)
suggest any usefull link and solution.

unable to get the data from facebook in codeigniter using hybridauth . Anyone Suggest?

I am using Hybridauth in Codeigniter and not able to get data from Facebook. When I print user_profile I get this response:
Hybrid_User_Profile Object(
[identifier] => myid [email] => [emailVerified] => [phone] =>
[address] => [country] => [region] => [city] => [zip] => )
well to get data from facebook you need to pass special permissions and then check what is coming from response

How can I get the author,price and title by knowing the ISBN search using amazon?

How can I get the author,price and title by knowing the ISBN search using amazon in codeigniter?
and
I been trying to sign up for the AProduct Advertising API registration for about 2 days, every time I get an error: We're sorry! There was an error processing your changes. Please try again. after account info step
how to get keys value of awsAccessKeyID, awsSecretKey, awsAssociateTag?
function getMetadataFromIsbn($isbn) {
// Get your own accesskey at http://aws.amazon.com/
$awsAccessKeyID = 'accesskey';
$awsSecretKey = 'secrete key';
$awsAssociateTag = 'Associate tag';
$host = 'ecs.amazonaws.com';
$path = '/onca/xml';
$args = array(
'AssociateTag' => $awsAssociateTag,
'AWSAccessKeyId' => $awsAccessKeyID,
'IdType' => 'ISBN',
'ItemId' => $isbn,
'Operation' => 'ItemLookup',
'ResponseGroup' => 'Medium',
'SearchIndex' => 'Books',
'Service' => 'AWSECommerceService',
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
'Version'=> '2009-01-06'
);

How to get module's title in Joomla 2.5?

Inside my module (from within php code), say mod_mymodule, how can I retrieve my module's title, in case an administrator has changed it from the module management page?
Is it possible to retrieve the "Status" and "Position" the same way as the title?
Inside the module, there are two helpful variables available:
$module and $params.
You are looking for $module->title.
Try the below code.
<?php
if ($module->showtitle)
{
echo '<h2>' .$module->title .'</h2>';
}
?>
You can access the following things.
stdClass Object
(
[id] => 18
[title] => Login Form
[module] => mod_login
[position] => left
[content] =>
[showtitle] => 1
[control] =>
[params] => greeting=1
name=0
[user] => 0
[name] => login
[style] =>
)
Reference Joomla URL:
1. http://docs.joomla.org/JModuleHelper/getModule
2. http://docs.joomla.org/Customising_the_way_modules_are_displayed
Updates - 22nd Dec 2016
You can use jimport to get the module.
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule( 'login' ); // Single
$module = JModuleHelper::getModule( 'mainmenu', 'Resources' ); // Multiple

J Factory::getUser() returning 0 id in joomla

I am using an ajax page in a module to save data. In that when I used JFactory::getUser() I'm getting the result as
JUser Object
(
[isRoot:protected] =>
[id] => 0
[name] =>
[username] =>
[email] =>
[password] =>
[password_clear] =>
[usertype] =>
[block] =>
[sendEmail] => 0
[registerDate] =>
[lastvisitDate] =>
[activation] =>
[params] =>
[groups] => Array()
[guest] => 1
[lastResetTime] =>
[resetCount] =>
[_params:protected] => JRegistry Object
(
[data:protected] => stdClass Object ()
)
[_authGroups:protected] =>
[_authLevels:protected] =>
[_authActions:protected] =>
[_errorMsg:protected] =>
[_errors:protected] => Array()
[aid] => 0
As have logged in before running this code, why is this still returning 0 user id. Can any one help me on this....
The response you are getting from JFactory::getUser() is either the current JUser-object (related to your session) oder an empty JUser-object for guests.
So in your case you are either not logged in or not loading Joomla properly.
The only php-files you should speak to are index.php and administrator/index.php, which are loading all necessary files and do what you want. (If you are using some CLI scripts you may have other options)
You can find more informations about Ajax on Joomla Documentation
I had a similar problem, it turned out to be a problem with the cookie domain, I was logged into the site using the domain example.com but accessing the AJAX URL using www.example.com. Just changing the domains so that they matched solved the problem.
In my experience
$user = JFactory::getUser();
$id = $user->id;
will always return a positve user id if the user is logged in, regardless of whether they are an admin user or not, and 0 if they are not logged in. So if you are getting 0 when you think that you are logged in, it has to be a cookie problem of some sort, or the Joomla session is not correctly started, eg by not accessing the site through index.php.

Resources