{"id":1420,"date":"2011-09-15T14:57:43","date_gmt":"2011-09-15T19:57:43","guid":{"rendered":"http:\/\/puchunguis.com\/blog\/?p=1420"},"modified":"2011-09-15T15:25:21","modified_gmt":"2011-09-15T20:25:21","slug":"api-de-google-plus-con-php","status":"publish","type":"post","link":"https:\/\/www.jorgealdana.pro\/blog\/informatica-computacion\/api-de-google-plus-con-php\/","title":{"rendered":"API de Google Plus con PHP"},"content":{"rendered":"<p><a href=\"https:\/\/484c2a6d15c399b70beb-b1e2a15a3df201703b71bb9b31acda05.ssl.cf5.rackcdn.com\/2011\/09\/google_plus_0711-1.jpg\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/484c2a6d15c399b70beb-b1e2a15a3df201703b71bb9b31acda05.ssl.cf5.rackcdn.com\/2011\/09\/google_plus_0711-1-150x150.jpg\" alt=\"\" title=\"google_plus_0711 (1)\" width=\"150\" height=\"150\" class=\"alignleft size-thumbnail wp-image-1424\" \/><\/a> Por fin y despu\u00e9s de la espera, se ha liberado el API de Google+, y podr\u00e1n implementarlo con PHP lo primero que necesitaremos, evidentemente, es la API oficial de Google, que podemos descargar desde <a href=\"http:\/\/code.google.com\/p\/google-api-php-client\/\" target=\"_blank\" rel=\"noopener\">CodeGoogle<\/a>. Descomprimimos el archivo y lo subimos a nuestro servidor.<\/p>\n<p>Ten en cuenta que GooglePlus por el momento solo incluye permisos de lectura y no incluye los circulos.<\/p>\n<p>1.- Registra tu cuenta, para obtener tu AccessToken en <a href=\"https:\/\/code.google.com\/apis\/accounts\/docs\/OAuth2.html#Registering\" target=\"_blank\" rel=\"noopener\">https:\/\/code.google.com\/apis\/accounts\/docs\/OAuth2.html#Registering<\/a> o en <a href=\"https:\/\/code.google.com\/apis\/console\/?api=plus\" target=\"_blank\" rel=\"noopener\">https:\/\/code.google.com\/apis\/console\/?api=plus<\/a><\/p>\n<p> &#8211; Desde \u00abInicio Proyecto\u00bb, activa el acceso a \u00abGoogle + API\u00bb.<br \/>\n &#8211; Haga clic en \u00abAcceso a la API\u00bb en la columna de la izquierda<br \/>\n &#8211; Haga clic en el bot\u00f3n \u00abCrear una ID OAuth2\u00bb<br \/>\n &#8211; Ingresa el nombre de tu aplicaci\u00f3n y haz clic en \u00abSiguiente\u00bb<br \/>\n &#8211; Seleccione \u00abWeb Application\u00bb como el \u00abtipo de aplicaciones\u00bb<br \/>\n &#8211; Haz clic en \u00abCrear ID de cliente\u00bb<br \/>\n &#8211; Haz clic en \u00abEditar&#8230;\u00bb para su ID de cliente nuevo<br \/>\n &#8211; Bajo la \u00abdirecci\u00f3n de devoluci\u00f3n de llamada\u00bb, introduzca la direcci\u00f3n URL completa para su aplicaci\u00f3n PHP (ejemplo https:\/\/www.jorgealdana.pro\/blog\/googleplus\/index.php).<\/p>\n<p>2.- Puedes utilizar el cliente oficial de Google para OAuth en: <a href=\"http:\/\/google-api-php-client.googlecode.com\/files\/google-api-php-client-0.4.4.tar.gz\" target=\"_blank\" rel=\"noopener\">http:\/\/google-api-php-client.googlecode.com\/files\/google-api-php-client-0.4.4.tar.gz<\/a><\/p>\n<p>Ejemplo para obtener actividades de tu cuenta:<\/p>\n<pre name=\"code\" class=\"php\">\r\n<p>&lt;?php<\/p>\r\n<p>require_once 'google-api-php-client\/src\/apiClient.php';<br \/>\r\n  require_once 'google-api-php-client\/src\/contrib\/apiPlusService.php';<\/p>\r\n<p>session_start();<\/p>\r\n<p>$client = new apiClient();<br \/>\r\n  $client-&gt;setApplicationName(&quot;Google+ PHP Starter Application&quot;);<br \/>\r\n  \/\/ VISITA https:\/\/code.google.com\/apis\/console PARA GENERAR TU KEY<br \/>\r\n  \/\/ oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.<br \/>\r\n   $client-&gt;setClientId('AQUI VA TU oauth2_client_id');<br \/>\r\n   $client-&gt;setClientSecret('AQUI VA TU oauth2_client_secret');<br \/>\r\n   $client-&gt;setRedirectUri('AQUI VA TU oauth2_redirect_uri');<br \/>\r\n   $client-&gt;setDeveloperKey('AQUI VA TU developer_key');<br \/>\r\n  $client-&gt;setScopes(array('https:\/\/www.googleapis.com\/auth\/plus.me'));<br \/>\r\n  $plus = new apiPlusService($client);<\/p>\r\n<p>if (isset($_REQUEST['logout'])) {<br \/>\r\n  unset($_SESSION['access_token']);<br \/>\r\n  }<\/p>\r\n<p>if (isset($_GET['code'])) {<br \/>\r\n  $client-&gt;authenticate();<br \/>\r\n  $_SESSION['access_token'] = $client-&gt;getAccessToken();<br \/>\r\n  header('Location: http:\/\/' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);<br \/>\r\n  }<\/p>\r\n<p>if (isset($_SESSION['access_token'])) {<br \/>\r\n  $client-&gt;setAccessToken($_SESSION['access_token']);<br \/>\r\n  }<\/p>\r\n<p>if ($client-&gt;getAccessToken()) {<br \/>\r\n  $me = $plus-&gt;people-&gt;get('me');<\/p>\r\n<p> $optParams = array('maxResults' =&gt; 100);<br \/>\r\n  $activities = $plus-&gt;activities-&gt;listActivities('me', 'public', $optParams);<\/p>\r\n<p> \/\/ The access token may have been updated lazily.<br \/>\r\n  $_SESSION['access_token'] = $client-&gt;getAccessToken();<br \/>\r\n  } else {<br \/>\r\n  $authUrl = $client-&gt;createAuthUrl();<br \/>\r\n  }<br \/>\r\n  ?&gt;<br \/>\r\n  &lt;!doctype html&gt;<br \/>\r\n  &lt;html&gt;<br \/>\r\n  &lt;head&gt;<br \/>\r\n  &lt;style media=&quot;all&quot; type=&quot;text\/css&quot;&gt;<br \/>\r\n  body {<br \/>\r\n  font-family: Arial,sans-serif;<br \/>\r\n  margin: auto;<br \/>\r\n  }<\/p>\r\n<p>.box {<br \/>\r\n  border: .5em solid #E3E9FF;<br \/>\r\n  -webkit-box-orient: vertical;<br \/>\r\n  -webkit-box-align: center;<br \/>\r\n  -moz-box-orient: vertical;<br \/>\r\n  -moz-box-align: center;<br \/>\r\n  display: block;<br \/>\r\n  box-orient: vertical;<br \/>\r\n  box-align: center;<br \/>\r\n  width: 350px;<br \/>\r\n  height: auto;<br \/>\r\n  margin: auto;<br \/>\r\n  padding: 10px;<br \/>\r\n  word-wrap: break-word;<br \/>\r\n  text-overflow: ellipsis;<br \/>\r\n  }<\/p>\r\n<p>.me {<br \/>\r\n  -webkit-box-flex: 1;<br \/>\r\n  -moz-box-flex: 1;<br \/>\r\n  box-flex: 1;<br \/>\r\n  width: 100px;<br \/>\r\n  }<\/p>\r\n<p>.activities {<br \/>\r\n  -webkit-box-flex: 2;<br \/>\r\n  -moz-box-flex: 2;<br \/>\r\n  box-flex: 2;<br \/>\r\n  width:100%;<br \/>\r\n  }<\/p>\r\n<p>.activity {<br \/>\r\n  margin: 10px;<br \/>\r\n  }<\/p>\r\n<p>header {<br \/>\r\n  color:#000;<br \/>\r\n  padding:2px 5px;<br \/>\r\n  font-size:100%;<br \/>\r\n  width: 400px;<br \/>\r\n  margin: auto;<br \/>\r\n  text-align: center<br \/>\r\n  }<\/p>\r\n<p>header h1.logo {<br \/>\r\n  margin:6px 0;<br \/>\r\n  padding:0;<br \/>\r\n  cursor:pointer;<br \/>\r\n  font-size:24px;<br \/>\r\n  line-height:20px;<br \/>\r\n  }<\/p>\r\n<p>.login {<br \/>\r\n  font-size: 200%;<br \/>\r\n  display: block;<br \/>\r\n  margin: auto;<br \/>\r\n  cursor: pointer;<br \/>\r\n  text-align: center;<br \/>\r\n  font-weight: bold;<br \/>\r\n  color: #2779AA;<br \/>\r\n  line-height: normal;<br \/>\r\n  }<\/p>\r\n<p>.logout {<br \/>\r\n  font-weight: normal;<br \/>\r\n  padding-top: -5px;<br \/>\r\n  margin-top: 0px;<br \/>\r\n  }<br \/>\r\n  &lt;\/style&gt;<br \/>\r\n  &lt;\/head&gt;<br \/>\r\n  &lt;body&gt;<br \/>\r\n  &lt;header&gt;&lt;h1&gt;Google+ Sample App&lt;\/h1&gt;&lt;\/header&gt;<br \/>\r\n  &lt;div class=&quot;box&quot;&gt;<br \/>\r\n  <br \/>\r\n  &lt;?php if(isset($me) &amp;&amp; isset($activities)): ?&gt;<br \/>\r\n  &lt;div class=&quot;me&quot;&gt;<br \/>\r\n  &lt;a rel=&quot;me&quot; href=&quot;&lt;?php echo $me['url'] ?&gt;&quot;&gt;&lt;?php print $me['displayName'] ?&gt;&lt;\/a&gt;<br \/>\r\n  &lt;div&gt;&lt;img src=&quot;&lt;?php echo $me['image']['url'];?&gt;?sz=82&quot; \/&gt;&lt;\/div&gt;<br \/>\r\n  &lt;\/div&gt;<\/p>\r\n<p>&lt;div class=&quot;activities&quot;&gt;Your Activities:<br \/>\r\n  &lt;?php foreach($activities['items'] as $activity): ?&gt;<br \/>\r\n  &lt;div class=&quot;activity&quot;&gt;<br \/>\r\n  &lt;a href=&quot;&lt;?php print $activity['url'] ?&gt;&quot;&gt;&lt;?php print $activity['title'] ?&gt;&lt;\/a&gt;<br \/>\r\n  &lt;\/div&gt;<br \/>\r\n  &lt;?php endforeach ?&gt;<br \/>\r\n  &lt;\/div&gt;<br \/>\r\n  &lt;?php endif ?&gt;<br \/>\r\n  &lt;?php<br \/>\r\n  if(isset($authUrl)) {<br \/>\r\n  print &quot;&lt;a class='login' href='$authUrl'&gt;Connect Me!&lt;\/a&gt;&quot;;<br \/>\r\n  } else {<br \/>\r\n  print &quot;&lt;a class='logout' href='?logout'&gt;Logout&lt;\/a&gt;&quot;;<br \/>\r\n  }<br \/>\r\n  ?&gt;<br \/>\r\n  &lt;\/div&gt;<br \/>\r\n  &lt;\/body&gt;<br \/>\r\n  &lt;\/html&gt;<\/p>\r\n\r\n<\/pre>\n<p>Estas son las direcciones para solicitudes directas:<\/p>\n<p>https:\/\/www.googleapis.com\/plus\/v1\/people\/107375088959448261459?key=TUAPIKEY<br \/>\nhttps:\/\/www.googleapis.com\/plus\/v1\/people\/107375088959448261459\/activities\/public?key=TUAPIKEY<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Por fin y despu\u00e9s de la espera, se ha liberado el API de Google+, y podr\u00e1n implementarlo con PHP lo primero que necesitaremos, evidentemente, es la API oficial de Google, que podemos descargar desde CodeGoogle. Descomprimimos el archivo y lo subimos a nuestro servidor. Ten en cuenta que GooglePlus por el momento solo incluye permisos de lectura y no incluye los circulos. 1.- Registra tu cuenta, para obtener tu AccessToken en https:\/\/code.google.com\/apis\/accounts\/docs\/OAuth2.html#Registering o en https:\/\/code.google.com\/apis\/console\/?api=plus &#8211; Desde \u00abInicio Proyecto\u00bb, activa el acceso a \u00abGoogle + API\u00bb. &#8211; Haga clic en \u00abAcceso a la API\u00bb en la columna de la izquierda <\/p>\n","protected":false},"author":1,"featured_media":1424,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[2464,2483,2482,2473,2479,2475,2471,2476,2465,2477,2474,40,2468,2467,2484,2469,2470,2485,2480,2486,2481,2466,2472,2478],"class_list":["post-1420","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-informatica-computacion","tag-api-de-google-plus","tag-api-de-google-plus-en-espanol","tag-api-de-google-plus-php","tag-api-google-plus-net","tag-api-google-plus-c","tag-api-google-plus-tutorial","tag-api-graph-google-plus","tag-api-key-de-google-plus","tag-api-key-google-plus","tag-api-para-google-plus","tag-clave-api-google-plus","tag-google","tag-google-plus-apps","tag-google-plus-developer","tag-google-plus-developers-plataforma-para-probar-api","tag-google-plus-php-api","tag-google-plus-rest-api","tag-google-php","tag-obtener-api-key-google-plus","tag-php-google","tag-plataforma-para-probar-api-en-google-plus","tag-plataforma-para-probar-api-google-plus","tag-python-google-plus-api","tag-tutorial-api-google-plus","has_thumb"],"_links":{"self":[{"href":"https:\/\/www.jorgealdana.pro\/blog\/wp-json\/wp\/v2\/posts\/1420","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jorgealdana.pro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jorgealdana.pro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jorgealdana.pro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jorgealdana.pro\/blog\/wp-json\/wp\/v2\/comments?post=1420"}],"version-history":[{"count":13,"href":"https:\/\/www.jorgealdana.pro\/blog\/wp-json\/wp\/v2\/posts\/1420\/revisions"}],"predecessor-version":[{"id":1432,"href":"https:\/\/www.jorgealdana.pro\/blog\/wp-json\/wp\/v2\/posts\/1420\/revisions\/1432"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jorgealdana.pro\/blog\/wp-json\/wp\/v2\/media\/1424"}],"wp:attachment":[{"href":"https:\/\/www.jorgealdana.pro\/blog\/wp-json\/wp\/v2\/media?parent=1420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jorgealdana.pro\/blog\/wp-json\/wp\/v2\/categories?post=1420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jorgealdana.pro\/blog\/wp-json\/wp\/v2\/tags?post=1420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}