'模块'对象没有属性' GraphAPI'

时间:2014-03-26 10:09:15

标签: django facebook-graph-api

我是python中的新手。我希望facebook喜欢使用Facebook Graph API计数。但是图api中的问题。以下代码在ipython中运行但不在django中运行

 from django.http import HttpResponse, HttpResponseForbidden
 import requests # pip install requests
 import json
 import facebook
 from prettytable import PrettyTable
 from collections import Counter
 def tweet(request):
      ACCESS_TOKEN =   'CAACEdEose0cBAGqqZAQTaCoCnGn9jhUR42LAuxtZBHBZCPCsverUSIngAqYidbLMgQ8K0gCnOoGFRmYEZCMoTVL0SF   R0ZBKCi2TUZC8m8RXk4wAj1UQyu927GYXicFIXXv2zWVeKbPFXaGhqofwClOF7DHdewTL48ZCqy5ZBZBVsM1JopgpmGNldcNV9ZBbWtfZC4FwE7fWlCZAolwZDZD'
      print("ACCESS_TOKEN:",ACCESS_TOKEN)
      base_url = 'https://graph.facebook.com/me'
      fields = 'id,name'
      url = '%s?fields=%s&access_token=%s' % \
     (base_url, fields, ACCESS_TOKEN,)
     print(url)
     content = requests.get(url).json()
      print(json.dumps(content, indent=1))
      g = facebook.GraphAPI(ACCESS_TOKEN)
     friends = g.get_connections("me", "friends")['data']
     likes = { friend['name'] : g.get_connections(friend['id'], "likes")['data'] 
      for friend in friends }
            print(likes)
      friends_likes = Counter([like['name']
                     for friend in likes 
                       for like in likes[friend]
                           if like.get('name')])
       return HttpResponse(json.dumps(content, indent=1))

0 个答案:

没有答案