Created
February 26, 2017 08:46
-
-
Save randomradio/d3a58591f217ad86c9a22f594f4e84fd to your computer and use it in GitHub Desktop.
人人网照片导出样本script。renren.com image export sample script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# pip install renren | |
from renren import APIClient | |
import pprint | |
import json | |
import requests | |
def get_my_image(image_url, folder, name,): | |
img_data = requests.get(image_url).content | |
with open(name + '.jpg', 'wb') as handler: | |
handler.write(img_data) | |
if __name__ == "__main__": | |
# use your own key and secret | |
client = APIClient(app_key="00", app_secret="13213", | |
redirect_uri="http://graph.renren.com/oauth/login_success.html") | |
auth_url = client.get_authorize_url(scope=["read_user_album", "read_user_photo"]) | |
print auth_url | |
AUTHORIZATION_CODE = raw_input("pin: ") | |
r = client.request_access_token(AUTHORIZATION_CODE) | |
access_token = r["access_token"] # access token | |
expires_in = r["expires_in"] # access token expires in time | |
refresh_token = r["refresh_token"] # token used for refresh | |
print access_token | |
client.set_access_token(access_token) | |
# print client.user.get(userId="235526712") | |
albums_resp = client.album.list(ownerId="235526712") | |
albums_list = albums_resp["response"] | |
for album in albums_list: | |
print album["id"] | |
print album["name"] | |
print "----------------------" | |
album_to_download = ["487913359", "465805720", "465788637", "460983163"] | |
for aid in album_to_download: | |
pic_in_album = client.photo.list(albumId=aid, ownerId="235526712") | |
for image_object in pic_in_album["response"]: | |
for img in image_object["images"]: | |
image_name = image_object["id"] | |
print image_name | |
if img["size"] == "LARGE": | |
get_my_image(img["url"], aid, str(image_name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment