📜 ⬆️ ⬇️

Picasaweb API Authorization. We get a constant token

I bring to your attention the registration script on the picasaweb web service.
The API of this web service is quite powerful, and is a good helper for photographers and developers.
To date, there are lots of different libraries to work with the picasaweb API. But what if I need to use only a small part of the capabilities of this service? You can use existing libraries (despite their cumbersomeness), redo them for yourself, or write your own bicycle. I am a supporter of my two-wheeled solutions.
The script is elementary, but will require the connection of the curl library. I hope you have it installed and activated, otherwise we will not see good luck.

So the script itself:

 <?php //    $secure = 0; $session = 1; $scope = "http://picasaweb.google.com/data/"; $next = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; $temp = @$_GET['token']; if(!$temp) { echo "<h2><a href=\"https://www.google.com/accounts/AuthSubRequest?scope=$scope&session=$session&secure=$secure&next=$next\">   </a></h2>"; } else { //      $token = upgradeToken($temp); if ($token) { echo " <h4> : $temp </h4> <h4> : $token </h4> <a href=\"view.php\"> </a>"; } } function upgradeToken($temp) { $ch = curl_init("https://www.google.com/accounts/AuthSubSessionToken"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: AuthSub token="' . trim($temp) . '"' )); $result = curl_exec($ch); curl_close($ch); $splitStr = split("=", $result); return trim($splitStr[1]); } ?> 
<?php // $secure = 0; $session = 1; $scope = "http://picasaweb.google.com/data/"; $next = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; $temp = @$_GET['token']; if(!$temp) { echo "<h2><a href=\"https://www.google.com/accounts/AuthSubRequest?scope=$scope&session=$session&secure=$secure&next=$next\"> </a></h2>"; } else { // $token = upgradeToken($temp); if ($token) { echo " <h4> : $temp </h4> <h4> : $token </h4> <a href=\"view.php\"> </a>"; } } function upgradeToken($temp) { $ch = curl_init("https://www.google.com/accounts/AuthSubSessionToken"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: AuthSub token="' . trim($temp) . '"' )); $result = curl_exec($ch); curl_close($ch); $splitStr = split("=", $result); return trim($splitStr[1]); } ?>


Let me remind you that in order to receive a token, we need to send a request to the Google server with our data, go through the resolving link confirming the intention, and get the token (temporary) parameter from the het answer, exchange it to a permanent one by sending another request to the chicken.

This will be enough to get a constant token.
')
Then our hands are untied. Now, having this token and your account on this service, we can, for example, display the photos of the album.

Demonstration

And if you're interested, the script for the demo itself:


 <html> <head> <title>Picasaweb auth</title> <style> body { background: none repeat scroll 0 0 #333333; } h1 { color: #FFFFFF; font-family: arial,verdana,tahoma,georgia; font-size: 27px; font-weight: normal; text-align: center; } a span { color: #FFFFFF; display: block; text-align: center; } div { margin: 0 auto; width: 1000px; } img { border: 1px solid #FFFFFF; height: 150px; } </style> </head> <body> <h1> </h1> <div> 
<?php // id , $user = '108610163479261934253'; $album_id = '5715645011798556705'; $url = "http://picasaweb.google.com/data/feed/base/user/$user/albumid/$album_id?alt=rss&kind=photo&hl=en"; $key = '1/6GJoq6_b0D2Y8YBsUJ3y0vGWPgxDb9GshCS7iuSpqhE'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="'.$key.'"')); $response = curl_exec($ch); curl_close($ch); $xml = new SimpleXMLElement($response); ?> <?php foreach($xml->channel->item as $i): ?> <?php preg_match('#src\=\"http:\/\/(.*)\"#SUsi', $i->description, $min); ?> <a href="<?=$i->enclosure['url']; ?>?size=640" target="_blank"> <img src="http://<?=$min[1]; ?>" /> </a> <?php endforeach; ?>
</div> </body> </html>
<html> <head> <title>Picasaweb auth</title> <style> body { background: none repeat scroll 0 0 #333333; } h1 { color: #FFFFFF; font-family: arial,verdana,tahoma,georgia; font-size: 27px; font-weight: normal; text-align: center; } a span { color: #FFFFFF; display: block; text-align: center; } div { margin: 0 auto; width: 1000px; } img { border: 1px solid #FFFFFF; height: 150px; } </style> </head> <body> <h1> </h1> <div>
<?php // id , $user = '108610163479261934253'; $album_id = '5715645011798556705'; $url = "http://picasaweb.google.com/data/feed/base/user/$user/albumid/$album_id?alt=rss&kind=photo&hl=en"; $key = '1/6GJoq6_b0D2Y8YBsUJ3y0vGWPgxDb9GshCS7iuSpqhE'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="'.$key.'"')); $response = curl_exec($ch); curl_close($ch); $xml = new SimpleXMLElement($response); ?> <?php foreach($xml->channel->item as $i): ?> <?php preg_match('#src\=\"http:\/\/(.*)\"#SUsi', $i->description, $min); ?> <a href="<?=$i->enclosure['url']; ?>?size=640" target="_blank"> <img src="http://<?=$min[1]; ?>" /> </a> <?php endforeach; ?>
</div> </body> </html>
 <html> <head> <title>Picasaweb auth</title> <style> body { background: none repeat scroll 0 0 #333333; } h1 { color: #FFFFFF; font-family: arial,verdana,tahoma,georgia; font-size: 27px; font-weight: normal; text-align: center; } a span { color: #FFFFFF; display: block; text-align: center; } div { margin: 0 auto; width: 1000px; } img { border: 1px solid #FFFFFF; height: 150px; } </style> </head> <body> <h1> </h1> <div> 
<?php // id , $user = '108610163479261934253'; $album_id = '5715645011798556705'; $url = "http://picasaweb.google.com/data/feed/base/user/$user/albumid/$album_id?alt=rss&kind=photo&hl=en"; $key = '1/6GJoq6_b0D2Y8YBsUJ3y0vGWPgxDb9GshCS7iuSpqhE'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="'.$key.'"')); $response = curl_exec($ch); curl_close($ch); $xml = new SimpleXMLElement($response); ?> <?php foreach($xml->channel->item as $i): ?> <?php preg_match('#src\=\"http:\/\/(.*)\"#SUsi', $i->description, $min); ?> <a href="<?=$i->enclosure['url']; ?>?size=640" target="_blank"> <img src="http://<?=$min[1]; ?>" /> </a> <?php endforeach; ?>
</div> </body> </html>
<html> <head> <title>Picasaweb auth</title> <style> body { background: none repeat scroll 0 0 #333333; } h1 { color: #FFFFFF; font-family: arial,verdana,tahoma,georgia; font-size: 27px; font-weight: normal; text-align: center; } a span { color: #FFFFFF; display: block; text-align: center; } div { margin: 0 auto; width: 1000px; } img { border: 1px solid #FFFFFF; height: 150px; } </style> </head> <body> <h1> </h1> <div>
<?php // id , $user = '108610163479261934253'; $album_id = '5715645011798556705'; $url = "http://picasaweb.google.com/data/feed/base/user/$user/albumid/$album_id?alt=rss&kind=photo&hl=en"; $key = '1/6GJoq6_b0D2Y8YBsUJ3y0vGWPgxDb9GshCS7iuSpqhE'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="'.$key.'"')); $response = curl_exec($ch); curl_close($ch); $xml = new SimpleXMLElement($response); ?> <?php foreach($xml->channel->item as $i): ?> <?php preg_match('#src\=\"http:\/\/(.*)\"#SUsi', $i->description, $min); ?> <a href="<?=$i->enclosure['url']; ?>?size=640" target="_blank"> <img src="http://<?=$min[1]; ?>" /> </a> <?php endforeach; ?>
</div> </body> </html>
 <html> <head> <title>Picasaweb auth</title> <style> body { background: none repeat scroll 0 0 #333333; } h1 { color: #FFFFFF; font-family: arial,verdana,tahoma,georgia; font-size: 27px; font-weight: normal; text-align: center; } a span { color: #FFFFFF; display: block; text-align: center; } div { margin: 0 auto; width: 1000px; } img { border: 1px solid #FFFFFF; height: 150px; } </style> </head> <body> <h1> </h1> <div> 
<?php // id , $user = '108610163479261934253'; $album_id = '5715645011798556705'; $url = "http://picasaweb.google.com/data/feed/base/user/$user/albumid/$album_id?alt=rss&kind=photo&hl=en"; $key = '1/6GJoq6_b0D2Y8YBsUJ3y0vGWPgxDb9GshCS7iuSpqhE'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="'.$key.'"')); $response = curl_exec($ch); curl_close($ch); $xml = new SimpleXMLElement($response); ?> <?php foreach($xml->channel->item as $i): ?> <?php preg_match('#src\=\"http:\/\/(.*)\"#SUsi', $i->description, $min); ?> <a href="<?=$i->enclosure['url']; ?>?size=640" target="_blank"> <img src="http://<?=$min[1]; ?>" /> </a> <?php endforeach; ?>
</div> </body> </html>
<html> <head> <title>Picasaweb auth</title> <style> body { background: none repeat scroll 0 0 #333333; } h1 { color: #FFFFFF; font-family: arial,verdana,tahoma,georgia; font-size: 27px; font-weight: normal; text-align: center; } a span { color: #FFFFFF; display: block; text-align: center; } div { margin: 0 auto; width: 1000px; } img { border: 1px solid #FFFFFF; height: 150px; } </style> </head> <body> <h1> </h1> <div>
<?php // id , $user = '108610163479261934253'; $album_id = '5715645011798556705'; $url = "http://picasaweb.google.com/data/feed/base/user/$user/albumid/$album_id?alt=rss&kind=photo&hl=en"; $key = '1/6GJoq6_b0D2Y8YBsUJ3y0vGWPgxDb9GshCS7iuSpqhE'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="'.$key.'"')); $response = curl_exec($ch); curl_close($ch); $xml = new SimpleXMLElement($response); ?> <?php foreach($xml->channel->item as $i): ?> <?php preg_match('#src\=\"http:\/\/(.*)\"#SUsi', $i->description, $min); ?> <a href="<?=$i->enclosure['url']; ?>?size=640" target="_blank"> <img src="http://<?=$min[1]; ?>" /> </a> <?php endforeach; ?>
</div> </body> </html>


$ user, $ album_id and $ key (constant token) I substituted my own. You will have yours.

That's all. Thanks for attention.

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


All Articles