我試圖用Vontakte,mongoengine擺脫Vk.com的牆後的名單,Django的 這是我的看法,其中wallposts = vk.get('wall.get', owner_id=237897731, offset=0, count=10)
是Vk.com API調用:如何將VK.com API響應中的JSON保存到MongoDB?
import vkontakte
vk = vkontakte.API(token=access_token)
class VkWallPostListView(ListView):
model = VkWallPost
context_object_name = "vk_list"
def get_template_names(self):
return ["blog/vk_list.html"]
def get_queryset(self):
wallposts = VkWallPost.objects
if 'all_posts' not in self.request.GET:
wallposts = vk.get('wall.get', owner_id=237897731, offset=0, count=10)
for wallpost in wallposts:
wallpost.save()
#wallposts = wallposts.filter(text__startswith='RT')
tag = self.request.GET.get('tag', None)
if tag:
wallposts = wallposts.filter(tags=tag)
return wallposts
此外,在這種觀點我試圖實際通話後立即保存API調用的MongoDB的結果:
for wallpost in wallposts:
wallpost.save()
但在瀏覽器中,我看到了一個錯誤:
Exception Value:
'int' object has no attribute 'save'
Exception Location: c:\Users\JOOMLER\BitNami_DjangoStack\django_mongo_test\blog\views.py in get_queryset, line 109
如果我刪除這兩個字符串的週期都工作正常,並顯示來自VK.com在瀏覽器中的飛行數據。但我想保存它以備後用。所以,我認爲問題是如何保存到MongoDB的JSON響應?
這裏是討論https://plus.google.com/u/0/+VicNgrail/posts/f8YWYtdqGSz – 2014-09-13 18:28:17
我音響做 vk_posts = vk.get( 'wall.get',owner_id = 1519369,偏移= 0,計數= 5) 用於vk_post在vk_posts: 打印vk_post 我在控制檯得到了數1367次這樣 的項目{u'likes':{u'count':4,u'can_publish':1,u'can_like':1,u'user_likes':0},u'attachments':[{u'photo':{u 'access_key':u'dff779d5b0ebfa8818',u'src':u'http://cs540104.vk.me/c540103/v5401039 ....... u'from_id':71201089} – 2014-09-13 18:29:05