Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a Google App Engine user by their user_id

In GAE, can you look up a User with the User object's user_id?

In other words, is there something equivalent to:

from google.appengine.api.users import User

user = User.get_by_id(user_id)
like image 289
Brian M. Hunt Avatar asked Jun 22 '10 22:06

Brian M. Hunt


2 Answers

I don't think so. ... they certainly wouldn't just give you access to every holder of a google account!

The idea is that you store user ids as properties in your datastore, once they've logged in to your app.

There is a property type called UserProperty

http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html

So, you can query your list of users from your own datastore definition.

hth

like image 172
laher Avatar answered Oct 20 '22 01:10

laher


This seems to be the only post on the internet regarding this and since I was looking for a solution, I thought I'd post what I found here.

What amir75 said about using the UserProperty is fine for storing the User object itself returned by the google.appengine.users module.

But if you need to lookup a User by the user_id field instead of the default email field, usually something like user = User(email = '[email protected]')

You can use this to query by user_id. user = User(_user_id = 'validuserid') The valid user_id is something that you got earlier from calling user.user_id()

I'm not sure what amir75 is referring to about having access to all google accounts since the User object returned will only have the email address and nickname, and that too only if the user authorizes the application to access that information.

My use case for this is I want people to sign up on the site, but they need an administrator to confirm them for using the site. The form used by the administrator for confirming the users can use email id as the field to identify the checkbox for confirming the user, but given that it might change, the user_id seems to be a safer field to use.

like image 35
arunkumar Avatar answered Oct 20 '22 00:10

arunkumar