我正在getstream中发布活动并使用"来"将活动复制到不同的Feed中。
用于添加活动的代码段
self.client = stream.connect(settings.STREAM_API_KEY, settings.STREAM_API_SECRET)
user_id = 1
content_id = 5
user_feed = self.client.feed('user', user_id)
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)
代码片段,用于删除活动
user_feed.remove_activity(foreign_id=content_id)
一旦我通过上面的代码移除活动,它就会从" user:1"中移除活动。但不删除Feed#34;标签:4"和"标签:5"。
是否还有其他方法可以立即从"用户:1"和"标签:4"和"标签:5"。
答案 0 :(得分:1)
从Feed中删除项目可能需要一些时间。在我的测试脚本中(我基于上面的代码)我在所有三个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''}