Created
January 10, 2014 16:09
-
-
Save shiweifu/8357142 to your computer and use it in GitHub Desktop.
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 | |
# -*- coding: utf-8 -*- | |
from weibo import Client | |
import webbrowser | |
import json | |
def get_token(): | |
try: | |
s = open("token").read() | |
return json.loads(s) | |
except: | |
return "" | |
def main(): | |
API_KEY = u'2356093016' # app key | |
API_SECRET = u'97e5a2f088bc019e8dd2e642132035f3' # app secret | |
token = get_token() | |
if(token != ""): | |
c = Client(API_KEY, API_SECRET, "https://api.weibo.com/oauth2/default.html", token) | |
else: | |
c = Client(API_KEY, API_SECRET, "https://api.weibo.com/oauth2/default.html") | |
webbrowser.open(c.authorize_url) | |
code = raw_input() | |
c.set_code(code) | |
open("token", "w").write(json.dumps(c.token)) | |
# c.post('statuses/update', status='python sdk test') | |
f = open('pic.jpg', 'rb') | |
c.post('statuses/upload', status='new avatar!', pic=f) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment