#Wadayouneedadoo
run sudo python2 ./server.py
go to http://locahost/albums.py
click authorize
view image code!
#!/usr/bin/env python2 | |
from oauth2client.client import OAuth2WebServerFlow | |
import gdata.photos.service | |
import os | |
print "Content-type: text/html" | |
print "<title>Google Photos Browser</title>" | |
flow = OAuth2WebServerFlow(client_id='231197837344-skdbuop575r1f55cm9u1v839ph6oc0dd.apps.googleusercontent.com', | |
client_secret='--l0NnAmQN1pZBBcWX9WV-BC', | |
scope='https://picasaweb.google.com/data/', | |
redirect_uri='http://localhost/albums.py') | |
query = os.environ.get("QUERY_STRING", "None") | |
if query.split("=")[0] == "code": | |
credentials = flow.step2_exchange(query.split("=")[1]) | |
gd_client = gdata.photos.service.PhotosService(additional_headers={'Authorization' : 'Bearer %s' % credentials.access_token}) | |
albums = gd_client.GetUserFeed() | |
for album in albums.entry: | |
print '<p>%s (%s)</p>' % (album.title.text,album.numphotos.text) | |
photos = gd_client.GetFeed( | |
'/data/feed/api/user/%s/albumid/%s?kind=photo' % ( | |
"rawashbourne", album.gphoto_id.text)) | |
for photo in photos.entry: | |
print '<pre><img src="%s" alt="%s"></img></pre>' % ( | |
photo.content.src, photo.title.text) | |
else: | |
auth_uri = flow.step1_get_authorize_url() | |
print "<a href="+auth_uri+">authorize the program</a>" |
#Wadayouneedadoo
run sudo python2 ./server.py
go to http://locahost/albums.py
click authorize
view image code!
#!/usr/bin/env python2 | |
import BaseHTTPServer | |
import CGIHTTPServer | |
import cgitb | |
cgitb.enable() # This line enables CGI error reporting | |
server = BaseHTTPServer.HTTPServer | |
class customHandler(CGIHTTPServer.CGIHTTPRequestHandler): | |
def do_GEsdT( self ): | |
self.send_response(200) | |
self.send_header( 'Content-type', 'text/html' ) | |
self.end_headers() | |
self.wfile.write( open('index.html').read() ) | |
handler = customHandler | |
server_address = ("", 80) | |
handler.cgi_directories = ["/"] | |
httpd = server(server_address, handler) | |
httpd.serve_forever() |