從Feed中刪除項目可能需要一些時間。在我的測試腳本中(我基於上面的代碼),我在所有三個提要的remove_activity()
調用和.get()
調用之間使用了一秒睡眠,並且它們全部恢復爲空。
import stream
import time
STREAM_API_KEY='foo'
STREAM_API_SECRET='bar'
def print_feeds(f1,f2,f3):
print 'f1'
print f1.get()
print 'f2'
print f2.get()
print 'f3'
print f3.get()
client = stream.connect(STREAM_API_KEY, STREAM_API_SECRET)
user_id = 1
content_id = 5
user_feed = client.feed('user', user_id)
tag4 = client.feed('tag', 4)
tag5 = client.feed('tag', 5)
to_stream = ["tag:4", "tag:5"]
activity = { 'actor': user_id, 'verb': "post", 'object': content_id, 'foreign_id': content_id, 'to': to_stream }
user_feed.add_activity(activity)
time.sleep(1)
print '*** after adding to feed ***'
print_feeds(user_feed, tag4, tag5)
user_feed.remove_activity(foreign_id=content_id)
time.sleep(1)
print '*** after deleting from feed ***'
print_feeds(user_feed, tag4, tag5)
這是輸出我得到:
*** after adding to feed ***
f1 (user feed)
{u'duration': u'22ms', u'results': [{u'origin': None, u'target': None, u'object': u'5', u'actor': u'1', u'to': [u'tag:4', u'tag:5'], u'verb': u'post', u'time': datetime.datetime(2017, 5, 30, 18, 40, 2, 556596), u'foreign_id': u'5', u'id': u'64589b08-4567-11e7-8080-8001531a35e4'}], u'next': u''}
f2 (tag 4)
{u'duration': u'16ms', u'results': [{u'origin': None, u'target': None, u'object': u'5', u'actor': u'1', u'to': [u'tag:4', u'tag:5'], u'verb': u'post', u'time': datetime.datetime(2017, 5, 30, 18, 40, 2, 556596), u'foreign_id': u'5', u'id': u'64589b08-4567-11e7-8080-8001531a35e4'}], u'next': u''}
f3 (tag 5)
{u'duration': u'25ms', u'results': [{u'origin': None, u'target': None, u'object': u'5', u'actor': u'1', u'to': [u'tag:4', u'tag:5'], u'verb': u'post', u'time': datetime.datetime(2017, 5, 30, 18, 40, 2, 556596), u'foreign_id': u'5', u'id': u'64589b08-4567-11e7-8080-8001531a35e4'}], u'next': u''}
*** after deleting from feed ***
f1 (user feed)
{u'duration': u'17ms', u'results': [], u'next': u''}
f2 (tag 4)
{u'duration': u'11ms', u'results': [], u'next': u''}
f3 (tag 5)
{u'duration': u'14ms', u'results': [], u'next': u''}
你好@iandouglas。唯一的區別在這裏。 ('tag',4) tag5 = client.feed('tag',5) – ramchauhan
tag4 = client.feed('tag','tag' ,4) tag5 = client.feed('tag',5) to_stream = [「tag:4」,「tag:5」] activity = {'actor':user_id,'verb':「post」, 'object':content_id,'foreign_id':content_id,'to':to_stream}並且我們沒有用這兩行初始化這些提要tag4 = client.feed('tag',4) tag5 = client.feed('tag ',5)。我們只是製作to_stream = [「tag:4」,「tag:5」]並添加活動。這是強制性添加飼料通過做tag4 = client.feed('tag',4) tag5 = client.feed('tag',5),然後使to_stream列表? – ramchauhan
不,它根本不是強制性的,我只是實例化這些提要,以便我可以單獨提取它們以查看它們是否爲空。 – iandouglas