存档

文章标签 ‘Open Social’

080116 opensocial笔记

2009年1月17日 康爷 没有评论

获取个人信息和发送request的代码的注释:

    url="http://feeds.feedburner.com/solidot"
    request = urllib2.urlopen(url)
    content = request.read()
    feed=feedparser.parse(content)
    entries=feed.entries
    for i in range(0,len(entries)):
        if entries[i].slash_section == "science":
            title = entries[i].title
            print "%d.%s" % (i,title)
    pub_list = []
    pub_list = input("pub id?")
    for pub_id in pub_list:
        #print "%d.%s" % (pub_id,entries[pub_id].title)
        des = entries[pub_id].description
        end = des.index("

")
        if end == -1:
            des = des
        else:
            des = des[0:end]
        postvalues = "title=%s&text=%s&board=Test" % (entries[pub_id].title,des)
        postvalues = postvalues.encode('gbk')
        request = urllib2.Request(urlList['post'], postvalues)
        opener.open(request).read()
        time.sleep(6)
        print "%d.%s" % (pub_id,entries[pub_id].title)
        print "sleep 6 second"
/** * Request the OWNER and OWNER's friends. */function request() {  var idspec = opensocial.newIdSpec({ "userId" : "OWNER", "groupId" : "FRIENDS" });  var req = opensocial.newDataRequest();                        //新建一个request  req.add(req.newFetchPersonRequest("OWNER"), "get_owner"); //添加获取owner的request,注意,get_owner是这个request的key  req.add(req.newFetchPeopleRequest(idspec), "get_friends"); //同样get_friends也是一个key,在response时可以用来获取数据  req.send(response);};

 

/** * Parses the response and generates html to list the names of the owner and * his or her friends. * * @param {Object} dataResponse Friend information that was requested. */function response(dataResponse) {  var owner = dataResponse.get('get_owner').getData();                    //通过key来获取数据  var friends = dataResponse.get('get_friends').getData();   var html = 'Friends of ' + owner.getDisplayName();  html += ':<br><ul>';  friends.each(function(person) {      html += '<li>' + person.getDisplayName() + '</li>';  });  html += '</ul>';  document.getElementById('message').innerHTML = html;};

分类: Google 标签: