My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Links

PyManyou: Manyou平台API的Python封装

PyManyou是一个对Manyou平台API的Python封装,基于PyFacebook,使用和风格同PyFacebook保持一致。PyManyou可以独立使用,同时支持Django,并且兼容Google App Engine。

快速使用帮助

和Django结合使用

# 下载PyManyou代码,把manyou整个目录放到Django项目的根下 # 编辑settings.py

MIDDLEWARE_CLASSES = (
    ...
    'manyou.djangomy.ManyouMiddleware',
    ...
)

MANYOU_API_KEY = 'your_api_key'
MANYOU_SECRET_KEY = 'your_api_secret'
MANYOU_APP_ID = "app_id" #Manyou app的ID,app的url里"?id=xxxxx"部分就是app id
MANYOU_CALLBACK_PATH = "/path/" #相对于服务器根目录的callback_path
MANYOU_INTERNAL = True

# 然后就可以在view函数里这样调用PyManyou

import manyou.djangomy as my
from django.utils import simplejson

@my.require_add()
def foo(request):
    my = request.manyou
    #make api calls now
    info = my.user.getInfo(uids=[my.uid],
                    fields=['uch_id','name','handle','site','sex','birthday','blood_type','relationship_status','current_location','hometown_location','has_added_app','privilege'])
    logging.debug('Got user info: %s' % info)
    
    logging.debug('Testing user.getLoggedInUser')
    info = my.user.getLoggedInUser()
    logging.debug('Got result: %s' % info)
    
    logging.debug('Testing user.isAppAdded')
    info = my.user.isAppAdded()
    logging.debug('Got result: %s' % info)
    
    logging.debug('Testing friend.get')
    info = my.friend.get()
    logging.debug('Got result: %s' % info)
    
    logging.debug('Testing friend.areFriends')
    info = my.friend.areFriends(uid1=my.uid, uid2='12345678')
    logging.debug('Got result: %s' % info)
    
    logging.debug('Testing friend.getAppUsers')
    info = my.friend.getAppUsers()
    logging.debug('Got result: %s' % info)
    
    logging.debug('Testing notification.send')
    info  = my.notification.send(uids=my.uid, msg='Hello Manyou!')
    logging.debug('Got result: %s' % info)
    
    logging.debug('Testing notification.get')
    info = my.notification.get()
    logging.debug('Got result: %s' % info)
    
    logging.debug('Testing feed.publishTemplatizedAction')
    info = my.feed.publishTemplatizedAction(title_template='{actor} is testing with {friend}',
                                            title_data=simplejson.dumps({'friend':'我'}),
                                            body_template='This is just a test. {sentence}',
                                            body_data=simplejson.dumps({'sentence':'请不要在意'}),
                                            image_1='http://photos-e.ak.facebook.com/photos-ak-sctm/genericv2b/393/51/01AwcA9ghX6pwAAAABAAAAAAAAAAA:.jpg',
                                            image_1_link='http://facebook.com',
                                            )
    logging.debug('Got result: %s' % info)

独立于任何web framework在python环境中使用

# 下载PyManyou代码,确保manyou目录在PYTHONPATH # 这样初始化一个Manyou实例:

...
my = Manyou(api_key="your_api_key", secret_key="your_secret_key", app_id="your_app_id", callback_path="app_callback_path", internal=True)
if not my.check_session(request):
    return my.redirect(my.get_add_url())
#make api calls now
friends = my.friends.get()
...

PyManyou默认使用JSON数据返回格式

2008年8月25日

v0.1版

  • 支持Manyou平台至今所有正式API
  • 已测试Google App Engine的部署
  • 需要更多的测试,欢迎报告问题
Powered by Google Project Hosting