Support » Plugin: WordPress Social Login » Will the Google API be updated? Current one will stop working in March

  • Resolved fariazz


    Hey there!

    Are there any plans to update the Google API?

    The current version as implemented in the plugin will stop working in March.

    Could you let us know if the plugin will or will not be updated to support this?

    Thanks! 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi,

    Google+ API (which will be shut down) seems to be only used to get user datas.
    The solution could be to use People API in place of Google+ API in hybridauth/Hybrid/Providers/Google.php

    I did the following modifications and it seems to be working.
    As I only need to get email, first name, last name and display name, it seems sufficient.

    Line 19 :
    public $scope = "profile";
    becomes :
    public $scope = "profile email";

    Line 29 :
    $this->api->api_base_url = "";
    becomes :
    $this->api->api_base_url = "";

    Line 73 to 101 :

    $response = $this->api->api( "" );

    becomes :

    $response = $this->api->api( ",emailAddresses" );
    if ( ! isset( $response->resourceName) || isset( $response->error ) ){
    	throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
    $this->user->profile->identifier    = (property_exists($response,'resourceName'))?$response->resourceName:((property_exists($response,'resourceName'))?$response->resourceName:"");
    $this->user->profile->firstName     = "";
    $this->user->profile->lastName      = "";
    $this->user->profile->displayName   = "";
    if (property_exists($response, 'names')) {
    	if (is_array($response->names) && count($response->names) > 0) {
    		$this->user->profile->firstName = isset($response->names[0]->givenName)?$response->names[0]->givenName:"";
    		$this->user->profile->lastName = isset($response->names[0]->familyName)?$response->names[0]->familyName:"";
    		$this->user->profile->displayName = isset($response->names[0]->displayName)?$response->names[0]->displayName:"";
    $this->user->profile->email         = "";
    if (property_exists($response, 'emailAddresses')) {
    	if (is_array($response->emailAddresses) && count($response->emailAddresses) > 0) {
    		$this->user->profile->email = isset($response->emailAddresses[0]->value)?$response->emailAddresses[0]->value:"";
    $this->user->profile->photoURL      = (property_exists($response,'image'))?((property_exists($response->image,'url'))?substr($response->image->url, 0, -2)."200":''):'';
    $this->user->profile->profileURL    = (property_exists($response,'url'))?$response->url:"";
    $this->user->profile->description   = (property_exists($response,'aboutMe'))?$response->aboutMe:"";
    $this->user->profile->gender        = (property_exists($response,'gender'))?$response->gender:""; 
    $this->user->profile->language      = (property_exists($response,'locale'))?$response->locale:'';

    And last important thing, to migrate old identifiers, I need to update existing entries in the database (change WPCUSTOMPREFIX to match your database) :
    update WPCUSTOMPREFIX_wslusersprofiles set identifier = concat('people/',identifier) where provider = 'Google' and identifier not like 'people/%';

    I knows it’s not the most elegant PHP code possible… but it seems to work.
    As I am not sure that it doesn’t break something elsewhere, I suggest you to try in a dev environment…
    Such modifications would be overriden if the plugin should be updated but it seems that it is no longer maintained.

    Or maybe a better way, in the previous code :

    $this->user->profile->identifier = (property_exists($response,'resourceName'))?$response->resourceName:((property_exists($response,'resourceName'))?$response->resourceName:"");
    becomes :
    $this->user->profile->identifier = str_replace("people/","",(property_exists($response,'resourceName'))?$response->resourceName:((property_exists($response,'resourceName'))?$response->resourceName:""));

    And you don’t have to update the database…


    Thank you so much. This worked a treat for me.
    One single issue which is outside the scope of your code it the profile picture/avatar.

    Now when users authenticate it is not showing the Avatar. Not sure if you would be able to assist me add their profile picture as the avatar on the site.

    Thanks again, you’re a champion!

    Thanks so much for sharing this! It worked like a charm on my end.

    The only step that is missing is you also need to enable the People API in your Google developer console for your existing project, it’s just one click:

    Otherwise it will give you an error message when you try to login (in that same error message, if you click on “Details” it will give you the exact link where you have to enable the People API).

    (note I’m only pulling the email, so I commented out all the lines about gender, age, etc)

    Thanks @papoum! Sterling work!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.