当前位置:编程学习 > python >>

新浪微博Python站內應用認證

      呢個新浪微博Python站內應用認證搞咗我兩日喇,睇咗N多Oauth2資料,寻日係度不停咁試,都試唔出個所以然,今日用python個解析器一句句試,終於搞掂。然後做到一半,微博PythonSDK嗰作者突然私信返我(我寻日問過佢),個SDK升級到1.0.9版,然後就冇然後喇... 我本來根據 http://blog.csdn.net/chenggong2dm/article/details/6613582 敲咗十幾行好核突嘅代易做图,改用新SDK幾行代易做图就搞掂... 以下放出基本代易做图。
 
[python]  
#!/usr/bin/python  
# -*- coding: utf-8 -*-  
# handlers.py  
  
import web  
import setting  
from weibo import APIClient  
from jinja2 import Environment, FileSystemLoader  
  
env = Environment(loader = FileSystemLoader('templates'))  
  
class Redirect:  
    def GET(self):  
        web.found( '/' )  
  
class Index:  
    def GET(self):  
        return env.get_template('goto_sina.html').render()  
    def POST(self):  
        # oauth2  
        c = APIClient(setting._APP_KEY, setting._APP_SECRET)  
        data = c.parse_signed_request( web.data().split("=")[1])  
        if 'oauth_token' not in data:  
            return env.get_template('unoauth.html').render()  
        c.set_access_token( data['oauth_token'], data['expires_in'])  
  
        sended = not 'rerror_code' in c.statuses.update.post(status=u'发微博')  
        return sended  
 
[python] 
# index.wsgi  
import sae  
import web  
from handlers import *  
  
# 404 & 500  
def notfound():  
    return web.notfound(  
            "Sorry, the page you were looking for was not found.")  
def internalerror():  
    return web.internalerror("Bad, bad server. No donut for you.")  
  
# url settings  
urls = (  
    '/?', 'Index',  
    '/.+', 'Redirect',  
)  
  
app = web.application(urls, globals())  
app.notfound = notfound  
#app.internalerror = internalerror  
application = sae.create_wsgi_app( app.wsgifunc() )  
 
unoauth.html
[html]  
<!DOCTYPE HTML>  
<html>  
<head>  
    <meta content="text/html; charset=gbk" http-equiv="Content-Type">  
    <title>unauth</title>  
    <style>  
        body{  
        background:url(http://css.tudouui.com/skin/2012sinaapp/img/bg_0.jpg) 50% top no-repeat #000;  
        }  
    </style>  
    <script language="JavaScript" src="http://tjs.sjs.sinajs.cn/t35/apps/opent/js/frames/client.js"></script>  
    <script language="JavaScript">   
        function authLoad(){  
            App.AuthDialog.show({  
                client_id : "3802881013",  
                redirect_uri : "http://apps.weibo.com/autotimer",  
                height: 120  
                });  
        }  
    </script>  
</head>  
<body onload="authLoad();">  
</body>  
</html>  
 
补充:Web开发 , Python ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,