How to get profile picture in Google Plus account?

I kind of create a site and I want to allow Google login. I do not want my clients to upload their profile photos to my site again. I have some idea on how to do this using facebook, but how do I get the profile picture from google plus account after the user has been authenticated through a Google account? Is there an API for this? If yes, welcome.

+4
source share
8 answers

We can easily get it with a plus client. When a plus client is connected ie

if(plusClient.isConnected){

            plusClient.getCurrentPerson().getImage().getUrl();

}

It will provide you the URL of the image.

+8
source

URL- Google, :

https://plus.google.com/s2/photos/profile/(user_id)?sz=150

, Google , .

URL-

https://www.googleapis.com/plus/v1/people/115950284...320?fields=image&key={YOUR_API_KEY}

URL- Google json,

:

{
    "image": 
    {
         "url": "https://lh3.googleusercontent.com/-OkM...AANA/ltpH4BFZ2as/photo.jpg?sz=50"
    }
}


Google ?

!!

+6

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

  • OAuth2, plus.login.
  • , people.get userId "me".
  • image.url
+2

+1, @Prisoner, plus.login, me.

URL- URL- .

<html>
  <head>
  <script src="https://apis.google.com/js/client:plusone.js"></script>
  </head>
  <body>
    <span id="signinButton">
      <span
        class="g-signin"
        data-callback="signinCallback"
        data-clientid="YOUR_CLIENT_ID"
        data-cookiepolicy="single_host_origin"
        data-requestvisibleactions="http://schemas.google.com/AddActivity"
        data-scope="https://www.googleapis.com/auth/plus.login">
      </span>
    </span>
    <script>
      function signinCallback (resp) {
        gapi.client.load('plus', 'v1', function() {
          gapi.client.plus.people.get({userId: 'me'}).execute(getProfilePic);
        });
      }
      function getProfilePic(person){
        console.log(person.image.url);
        console.log(person.cover.coverPhoto.url);
      }
    </script>
  </body>
</html>

, , , . , . API- people.get.

+1

Google+ pic

<?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();  
$id = $_POST['id'];  
$client = new apiClient();  
  $client->setApplicationName("Google+ PHP Starter Application");  
  // oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.  
  $client->setClientId('357142505911.apps.googleusercontent.com');  
  $client->setClientSecret('LbJa7YOJ1Th-e-TOosEJxI4A');  
  $client->setRedirectUri('http://www.w3resource.com/API/google-plus/example.php');  
  $client->setDeveloperKey('AIzaSyD3stLpkt7jJw0mkMsJtM9m_zrgg26rrsI');  
  $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($id);  
$optParams = array('maxResults' => 100);  
  $activities = $plus->activities->listActivities($id, '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)): ?>  
  <div class="me">  
  <p><a rel="me" href="<?php echo $me['url'] ?>"><?php print $me['displayName'] ?></a></p>  
  <p><?php print $me['tagline'] ?></p>   
  <p><?php print $me['aboutMe'] ?></p>   
  <div><img src="<?php echo $me['image']['url']; ?>?sz=82" /></div>  
  </div>  
  <div class="activities">Your Activities:  
  <?php foreach($activities['items'] as $activity): ?>  
  <div class="activity">  
  <p><a href="<?php print $activity['url'] ?>"><?php print $activity['title'] ?></a></p>  
  </div>  
  <?php endforeach ?>  
  </div>  
  <?php endif ?>  
  <?php  
  if(isset($authUrl)) {  
  print "<a class='login' href='$authUrl'>Connect Me!</a>";  
  } else {  
  //print "<a class='logout' href='?logout'>Logout</a>";  
  }  
  ?>  
  </div>  
  </body>  
  </html>  

: http://www.w3resource.com/API/google-plus/tutorial.php#

+1

Google,

public Uri getPhotoUrl()

URL- , , GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)}, requestProfile(); null . , .

Not guaranteed to be present for all users, even when configured, .

P/S: , Google+ , Google , , Google , .

0

API, http://www.avatarapi.com/, pic Google.

SOAP HTTP API: http://www.avatarapi.com/avatar.asmx

API , Google. .

0

The following URL is offered here :

https://plus.google.com/s2/photos/profile/GOOGLE-ID?sz=100

I have never seen this before in any documentation, so it may not have been supported by Google+, but it works now.

Maybe + class or + Prisoner can say something about supporting this URL in order to get pic profile?

-2
source

Source: https://habr.com/ru/post/1524978/


All Articles