How can I determine a user_id based on an email address in App Engine? -


The API for calculating the ID for the user account based on your email in the latest app engine SDK (1.2.1) The call is address. (The ID remains in the same state, even if the user changes their address later.) For information see this. However, I have a problem with this API call.

user_id () works by logged-in user (i.e. users.get_current_user) , but users.User () returns none for items created by the manufacturer. ** what gives?

For example, using the classic, this code does not work .

  & gt; & Gt; & Gt; Import Google.appengine.api.users & gt; & Gt; & Gt; Me = google.appengine.api.users.get_current_user ()> gt; & Gt; & Gt; Me users.User (email='jason.h.smith@gmail.com ', _ user_id =' 105261964646342707921 ') & gt; & Gt; & Gt; Me.user_id () '105261964646342707921' & gt; & Gt; & Gt; Any = google.appengine.api.users.User ('someone@gmail.com ') & gt; & Gt; & Gt; Any user User (email = 'someone@gmail.com') >> gt; & Gt; someone.. User_id () >> gt; & Gt; & Gt; Type (somebody.user_id ()) & lt; Type 'NoneType' & gt;  

I want an easy way to convert an email address to a user id. Before I can force this ID from Google; Or if this is not possible, why not?

Edit: This is the current solution.

Thank you for Nick Johnson for their reply. Here's his solution in action:

  & gt; & Gt; & Gt; Google.appengine.ext Import & Export DB from & gt; & Gt; & Gt; Google.appengine.api import user & gt; & Gt; & Gt; Class User (db.Model): ... user = db.UserProperty (required = true) ... & gt; & Gt; & Gt; Def email_to_userid (address): ... "" "Return a static user_id string based on an email address, or none ... address is not a valid / existing Google account." "... ... U = user user (address) ... key = user (user = u). Input () ... obj = User.get (key) ... back obj.user.user_id ( ) & Gt; & gt; Email_to_userid ('jason.h.smith@gmail.com') u'105261964646342707921 '& gt; & gt; Email_to_userid (' This is @ -a-invalid-email- Address')> No one is true  

The current solution is to create a user object, store it on a datastore and bring it again. If email matches a valid Google account, Return the unit to the user will also user_id field populated with the object.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -