php - get google account image using google api -
at first time,i'm trying google account profile picture using google api. have referred refer site.
so in google-plus-access.php:
<?php require_once 'google-api-php-client-master/src/google/autoload.php'; // or wherever autoload.php located session_start(); $client = new google_client(); $client->setapplicationname("google+ php starter application"); $client->setclientid('my_client_id'); $client->setclientsecret('my_secret_key'); $client->setredirecturi('http://localhost/g-api'); $client->setdeveloperkey('my_dev_key'); $client->setscopes(array('https://www.googleapis.com/auth/plus.me')); //$plus = new apiplusservice($client); $plus = $client -> createauthurl(); if(isset($_request['logout'])) { unset($_session['access_token']); } if(isset($_get['code'])) { echo $_get['code']; $client->authenticate(); $_session['access_token'] = $client->getaccesstoken(); header('location: http://' . $_server['http_host'] . $_server['php_self']); } if(isset($_session['access_token'])) { echo $_session['access_token']; $client->setaccesstoken($_session['access_token']); } if ($client->getaccesstoken()) { $me = $plus->people->get('me'); echo $me; $optparams = array('maxresults' => 100); $activities = $plus->activities->listactivities('me', 'public', $optparams); $_session['access_token'] = $client->getaccesstoken(); } else { $authurl = $client->createauthurl(); echo '<pre>'; print_r($authurl); // block running!!! echo '</pre>'; } echo "</br>";
?>
and in index.php:
<?php include('google-plus-access.php'); ?> <img src="<?php echo(substr($me['image']['url'],0,stripos($me['image']['url'],'?sz='))); ?>?sz=200" />
but i'm getting result as:
https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=http%3a%2f%2flocalhost%2fg-api&client_id=887633147241-8ragvhdi97lga3n829qogpl5aoima7l5.apps.googleusercontent.com&scope=https%3a%2f%2fwww.googleapis.com%2fauth%2fplus.me&access_type=online&approval_prompt=auto
in console i'm getting below error:
my output scree looking :
edit:
in console i'm getting get http://localhost/g-api/%3cbr%20/%3e%3cb%3enotice%3c/b%3e:%20%20undefined%20…/g-api/index.php%3c/b%3e%20on%20line%20%3cb%3e7%3c/b%3e%3cbr%20/%3e?sz=200 403 (forbidden)
this.
these things done in local.so body making me scared can't local , have create domain that.so kindly me this.
check code $me
created in if // block running!!!
in else.
you trying use $me hasn't been created.
if ($client->getaccesstoken()) { $me = $plus->people->get('me'); //daimto: doesn't run cant use echo $me; $optparams = array('maxresults' => 100); $activities = $plus->activities->listactivities('me', 'public', $optparams); $_session['access_token'] = $client->getaccesstoken(); } else { $authurl = $client->createauthurl(); echo '<pre>'; print_r($authurl); // block running!!! echo '</pre>'; }
you need create service, $plus->people->get('me');
isn't going work because $plus isn't google_service_plus
. should check out example found here user-sample.php
$googleplus = new google_service_plus($client); $userprofile = $googleplus->people->get('me');
Comments
Post a Comment