Picture property format using run with friends fb app

*爱你&永不变心* 提交于 2020-03-03 07:49:25

问题


I am editing the Runwithfriends FB sample app to build one of my own. It was working fine and I was making a few changes here and there. I took a break from it for about a fortnight but now when I try to access the app, I get a strange python error:

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\app\main.py in init_facebook(self=<main.RecentRunsHandler object>) 316 user_id=facebook.user_id, friends=friends, 317 access_token=facebook.access_token, name=me[u'name'], => 318 email=me.get(u'email'), picture=me[u'picture']) 319 user.put() 320 except KeyError, ex:

<..some portion clipped..>

class 'google.appengine.api.datastore_errors.BadValueError'>: Property picture must be a str or unicode instance, not a dict args = ('Property picture must be a str or unicode instance, not a dict',) message = 'Property picture must be a str or unicode instance, not a dict'"

I know this is a very generic error but its pointing to the following code. This code has always been there and I have never touched it. I really do not know where else to look now - I have searched exhaustively but couldnt find a clue. Sorry, if this is still too broad but I would be glad if you can tell me what other info can I provide to debug this :-(

def init_facebook(self):
    """Sets up the request specific Facebook and User instance"""
    facebook = Facebook()
    user = None

    # initial facebook request comes in as a POST with a signed_request
    if u'signed_request' in self.request.POST:
        facebook.load_signed_request(self.request.get('signed_request'))
        # we reset the method to GET because a request from facebook with a
        # signed_request uses POST for security reasons, despite it
        # actually being a GET. in webapp causes loss of request.POST data.
        self.request.method = u'GET'
        self.set_cookie(
            'u', facebook.user_cookie, datetime.timedelta(minutes=1440))
    elif 'u' in self.request.cookies:
        facebook.load_signed_request(self.request.cookies.get('u'))

    # try to load or create a user object
    if facebook.user_id:
        user = User.get_by_key_name(facebook.user_id)
        if user:
            # update stored access_token
            if facebook.access_token and \
                    facebook.access_token != user.access_token:
                user.access_token = facebook.access_token
                user.put()
            # refresh data if we failed in doing so after a realtime ping
            if user.dirty:
                user.refresh_data()
            # restore stored access_token if necessary
            if not facebook.access_token:
                facebook.access_token = user.access_token

        if not user and facebook.access_token:
            me = facebook.api(u'/me', {u'fields': _USER_FIELDS})
            try:
                friends = [user[u'id'] for user in me[u'friends'][u'data']]
                user = User(key_name=facebook.user_id,
                    user_id=facebook.user_id, friends=friends,
                    access_token=facebook.access_token, name=me[u'name'],
                    email=me.get(u'email'), picture=me[u'picture'])
                user.put()
            except KeyError, ex:
                pass # ignore if can't get the minimum fields

    self.facebook = facebook
    self.user = user

回答1:


Might have to do with the October 2012 Breaking Changes, quote:

/picture connection will return a dictionary when a callback is specified

We will start returning a dictionary containing the fields url, height, width, and is_silhouette when accessing the /picture connection for an object and specifying a callback property. Currently we just return the picture URL as a string.

So at this point in your code, where you are currently using picture=me[u'picture'], try accessing the url property of the picture dictionary instead. (If it has one; I can’t tell you for sure if this is applicable, since I don’t know if your code would be considered as having specified a callback property.)

If my assumption is correct, you could also enable the migration as described in the roadmap; but that will only make your app work in the old way until Oct. 3rd, so probably better to try and fix it right away.




回答2:


This is the way to get the picture:

picture=me[u'picture'][u'data'][u'url']


来源:https://stackoverflow.com/questions/11810397/picture-property-format-using-run-with-friends-fb-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!