python - Facebook login with Django -


i trying make facebook login in django (django 1.5 python 2.7.4) app , when try insert mysql database name of location of user logging in, table saves string parentheses , comma.

for example, if name of location (which access serializing json object , typing facebookmember['location']['name']) "turdera", when database value stored is"(u'turdera',)". happens when call model.save() function, doesn't happen when put location name directly on creating function (model.objects.get_or_create()).

this json:

{u'username': u'nombre.apellido', u'first_name': u'nombre',  u'last_name': u'apellido', u'verified': true,  u'name': u'nombre apellido', u'locale': u'en_us',  u'hometown': {u'id': u'104026979634226', u'name': u'turdera'},  u'work': [{u'position': {u'id': u'416940894990201',                           u'name': u'software developer'},             u'start_date': u'0000-00',             u'employer': {u'id': u'2176879549', u'name': u'empresa'}}],  u'email': u'email@hotmail.com',  u'updated_time': u'2013-08-09t17:30:17+0000', u'birthday': u'05/08/1987',  u'link': u'https://www.facebook.com/nombre.apellido',  **u'location': {u'id': u'104026979634226', u'name': u'turdera'}**,  u'gender': u'male', u'timezone': -3,  u'education': [{u'school': {u'id': u'18143905522',                              u'name': u'itmaster professional training'},                  u'type': u'college'},                 {u'school': {u'id': u'1089762591',                              u'name': u'pontifical catholic university'},                  u'type': u'college'}], u'id': u'655273058'} 

and code of save function:

        obj, created = member.objects.get_or_create(id=long(facebookmember['id']))          if (obj.first_login == none):             obj.first_login=datetime.now()          obj.first_name=facebookmember['first_name']         obj.last_name=facebookmember['last_name']         obj.email=facebookmember['email']         obj.locale=facebookmember['locale']         obj.access_token=facebookmember['access_token']         obj.location=(facebookmember['location']['name'] if 'location' in facebookmember else none),         obj.gender = utils().getinitialfromgender(facebookmember['gender'])         obj.date_of_birth = utils().getdateasyyyymmdd(facebookmember['birthday'])          obj.last_login=datetime.now()         obj.save() 

i remove "u" not parentheses , comma.

why have got comma @ end of line? making python think have tuple, not string:

>>> t = "s" if true else "b" >>> print t s >>> t = ("s" if true else "b") >>> print t s >>> t = ("s" if true else "b"), ('s',) 

so try:

obj.location=facebookmember['location'].get('name', none) 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -