Skip to content

Instantly share code, notes, and snippets.

@jwineinger
Created October 2, 2014 06:33
Show Gist options
  • Save jwineinger/c4e8031692486b9ec1db to your computer and use it in GitHub Desktop.
Save jwineinger/c4e8031692486b9ec1db to your computer and use it in GitHub Desktop.
Copy a picasa web album to a facebook album
import json
import requests
import gdata.photos.service
GOOGLE_ALBUM_ID = 0
GOOGLE_EMAIL = "you@gmail.com"
GOOGLE_PASSWORD = "hunter42"
FB_ACCESS_TOKEN = ""
FB_ALBUM_NAME = ""
FB_ALBUM_MESSAGE = ""
FB_ALBUM_PRIVACY = "ALL_FRIENDS" # {'EVERYONE', 'ALL_FRIENDS', 'FRIENDS_OF_FRIENDS', 'CUSTOM', 'SELF'}
def create_album(name, msg, privacy):
data = {
'name': name,
'message': msg,
'privacy': json.dumps({'value': privacy}),
}
params = {
'access_token': FB_ACCESS_TOKEN,
}
r = requests.post("https://graph.facebook.com/v2.1/me/albums", data=data, params=params)
return r.json()['id']
def add_photo(album_id, url):
data = {
'url': url,
#'no_story': True,
}
params = {
'access_token': FB_ACCESS_TOKEN,
}
r = requests.post("https://graph.facebook.com/v2.1/{album_id}/photos".format(album_id=album_id), data=data, params=params)
return r.json()['id']
fb_album_id = create_album(FB_ALBUM_NAME, FB_ALBUM_MESSAGE, FB_ALBUM_PRIVACY)
print "created facebook album with id=", fb_album_id
gd_client = gdata.photos.service.PhotosService(email=GOOGLE_EMAIL, password=GOOGLE_PASSWORD, source="copy-my-album")
gd_client.ProgrammaticLogin()
# use this to list all of your picasa-web albums and ids
# albums = gd_client.GetUserFeed(user='default')
# for album in albums.entry:
# print 'title: %s, number of photos: %s, id: %s' % (album.title.text, album.numphotos.text, album.gphoto_id.text)
photos = gd_client.GetFeed('/data/feed/api/user/default/albumid/{album_id}?kind=photo&imgmax=d'.format(album_id=GOOGLE_ALBUM_ID))
for photo in photos.entry:
content = photo.media.content[0]
add_photo(fb_album_id, content.url)
print "added", content.url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment