views:

905

answers:

2

I know this is simple, but I haven't used Zend_Gdata before, so I need some guidance. Please correct me if any of my assumptions are incorrect.

I am using Google Apps on my domain, so to get started, I would like to do something simple like listing all the users on the domain.

From what I understand, you need to use Zend_Gdata_ClientLogin instead of Zend_Gdata_AuthSub since I will be working with Zend_Gdata_Gapps. This is what I've got so far:

$client = Zend_Gdata_ClientLogin::getHttpClient('[email protected]', 'password');
$gdata = new Zend_Gdata_Gapps($client, 'mydomain.com');
$users = $gdata->retrieveAllUsers();

However, retrieveAllUsers() is throwing an exception with this message:

Expected response code 200, got 401 <HTML> <HEAD> <TITLE>Token invalid</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <H1>Token invalid</H1> <H2>Error 401</H2> </BODY> </HTML>

What does that mean? What am I doing wrong? I don't know if it matters, but I am running this PHP script locally, but my Google Apps are running on a remote server. I am using Zend Framework version 1.7.5.

Update: If anyone is wondering, there were a few more problems I ran into while doing this. I found out that in order to use Zend_Gdata, you have the enable the "Provisioning API" in the admin section of your Google Apps. I found out that I only have the standard (free) version of Google Apps, which means that the Provisioning API is not available to me unless I have a premier (paid) version of Google Apps.

+1  A: 

You're missing the service parameter, for Google Apps it's 'apps'

$client = Zend_Gdata_ClientLogin::getHttpClient('[email protected]', 'password','apps');
vartec
haven't tried yet, but I am confused about this. The documentation (which could be wrong) says its optional: "The optional third parameter is the name of the Google Data service...The default is "xapi", which is recognized by Google Data servers as a generic service name."
Andrew
Exactly. You're not trying do access "generic service", you're trying to access Apps.
vartec
Oooooh! Okay. I will try this out. Thanks!
Andrew
A: 

I've been learning how to access google spreadsheets and I pass a $service.

$service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
Hellonearthis