-
Notifications
You must be signed in to change notification settings - Fork 53
Tutorial of SNSPocket
This wiki is about How to use Objects in this project.
- snsbase
This class is a base class of all the plugins, if you want to write a new sns platform plugin, don't forget to derive from this class. It provide common authenticate and communicate method.
Have you notice that in plugin
folder and plugin_trial
folder, all the important classes are derived from SNSBase class? if you don't, open it, and view the source. You'll have a brief understanding.
- snspocket
What's pocket? Just a kind of container, you can regard it as a manager, who tries to help you to manage your all plugins, you can use this object to add
,delete
,save
and so on. In a nutshell, it's just a plugin manager.
- Message
After you got all of your messages from sns platform (such like RenRen,Weibo etc...), how to manage your messages (mainly parse message to unify message interface)? This class may help you well.
You can use these 3 class to implement and test your own plugins.
###Then, I'll list all the main python files, and attach a simple explaination
-
errors.py
: Errors or Exceptions for SNSAPI,It's very easy to understand. -
platform.py
: You can regard this file as a bootstrap loader, when import this file, it will load all the plugins fromplugin
andplugin_trail
folder -
snsbase.py
: ↑↑↑↑↑ I have disucessed. -
snsconf.py
: In this file , there are two classes One isSNSConf
another isSNSConfNoInstantiation
(an Exception class) ,SNSConf
is just a class which contains a hard code config information, don't be scared by lots of pili's explanation.... honestly It scared me %^&*... -
snscrypt.py
: just a crypt class , easy to understand -
snslog.py
: It just a log class, if you have android development experience , this class is much like log class in Android, and they have a same work principle.. -
snspocket.py
:↑↑↑↑↑ -
snstype.py
: Sns Message base class ↑↑↑↑↑ -
utils.py
: just some utils,(about json,html,etc...)
# -*- coding: utf-8 -*-
import snsapi
from snsapi import snstype
from snsapi.utils import console_output, console_input
from snsapi.snspocket import SNSPocket
from snsapi.snslog import SNSLog as logger
# 1.Create a SNSPocket object
sp = SNSPocket()
# some clear behavior , not so important
sp.list_channel()
sp.clear_channel()
#2. Got a new Channel
nc = sp.new_channel()
#3. Let's set the Channel as Sina Weibo and fill in some information,
# if you don't know why we have to fill in these params, try to get some knowledge from
# here:http://tools.ietf.org/html/rfc6749 (oauth)
nc["platform"] = "SinaWeiboStatus"
nc["app_secret"] = "96bcc1e00268d7e415c32212b3e197fb" //remember to change this to your own app_secret
nc["app_key"] = "3644324674" #and set the key //remember to change this to your own app_key
nc["channel_name"] = "test_weibo"
nc["auth_info"]["callback_url"] = "https://snsapi.ie.cuhk.edu.hk/aux/auth.php"
#4. Let's add this channel into our pocket
sp.add_channel(nc)
#4. As you know, we need to auth channel... invoke pocket's auth function.
sp.auth()
#5. Save our authorization into file
sp.save_config()
#6. Show what we have done
sp.list_channel()
#7. Get weibo messages.
status = sp.home_timeline()
for each in status:
print each,
Now you can see your weibo in your console ^_^ You must feel like a Geek , don't you?? have fun on this wiki. I'm Miracle, Github ID:xuanqinanhai .