Picasaweb API認証。 定数トークンを取得します

picasaweb Webサービスに登録するためのスクリプトを紹介します。

このWebサービスのAPIは非常に強力であり、写真家や開発者にとって優れたヘルパーです。

現在、picasaweb APIを操作するためのさまざまなライブラリがあります。 しかし、このサービスの機能のごく一部のみを使用する必要がある場合はどうなりますか? 既存のライブラリを使用して(面倒ではありますが)、自分でライブラリを改造したり、独自の自転車を作成したりできます。 私は二輪の決定の支持者です。

スクリプトは基本ですが、curlライブラリ接続が必要です。 インストールして有効化してください。そうしないと、幸運が見られません。



したがって、スクリプト自体:


 <?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]); } ?>













トークンを受信するには、データを使用してリクエストをGoogleサーバーに送信し、意図を確認する許容リンクをクリックして、パラメータ-get応答から受信したトークン(一時)を取得する必要があります。



これは、定数トークンを取得するのに十分です。



さらに私たちの手は解かれています。 これで、このトークンとこのサービスのアカウントがあれば、たとえばアルバムの写真を表示できます。



デモンストレーター



興味がある場合は、デモ自体のスクリプト:




 <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、および$ key(定数トークン)私は自分のものに置き換えました。 それらがあります。



以上です。 ご清聴ありがとうございました。



All Articles