开发者

App Engine ( Python ) and Provisioning API

I'm trying pull out a list of AllUsers from a Google Apps Domain. So far I've come to this http://code.google.com/googleapps/domain/gdata_provisioning_api_v2.0_reference_python.html A provisioning API that does do what I need but returns a UserFeed object? Some sort of Atom field?

Im not sure where to go from there.

Any advice on that?

UPDATE: So heres what I've come up with:


import gdata.apps.service
import gdata.alt.appengine
.....

service = gdata.apps.service.AppsService(email="someone@your_apps_domain.com", domain="your_apps_domain.com", password="mydoghasfleas")
        service.ProgrammaticLogin()
        gdata.alt.appengine.run_on_appengine(service) # i dont even think you need this

        users = service.RetrievePageOfUsers()

        for u in users.entry:

            self.response.out.write(u.login.user开发者_StackOverflow_name)

Also this is nifty for looking through these objects the Provisioning API makes I ran in to a problem. I was thinking since the atom response looked like this:

-- xml-- ns1:login xmlns:ns1="http://schemas.google.com/apps/2006" admin="false" agreedToTerms="true" changePasswordAtNextLogin="false" ipWhitelisted="false" suspended="false" userName="yosef" --xml--

I figured users.entry.userName <----note the camel case, it matches the xml response but it was user_name instead

anyway i used this to introspect the what the ProvisioningAPI created

def dump(obj): #pass the object into and it will show you all sorts of wonders 
  for attr in dir(obj):
    print "obj.%s = %s" % (attr, getattr(obj, attr))


Try this:

import gdata.apps
import gdata.apps.service
import gdata.alt.appengine

service = gs.AppsService(email="[[ account email with admin privs ]]",domain="[[ google apps domain ]]",password="[[ account password ]]")

gdata.alt.appengine.run_on_appengine(service)

service.ProgrammaticLogin()
users = service.RetrieveAllUsers()

for item in users.entry:
    print '----Username '+item.login.user_name' for user '+item.name.given_name+' '+item.name.family_name

This should print:

----Username john.doe for user John Doe
----Username jane.doe for user Jane Doe
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜