My company is new to Google Apps and we would like to publish a web
page on our intranet that will display a list of all the groups and
the users that are in that group. I know that there are example pages
on Google's code site, but I am still a little confused. Just to
start we decided to do some basic JavaScript code that would pull the
domain's contacts feed and output it to the page. When I log in I can
see my groups and the contacts under the group. It prints out the
list of groups and email address but not in the correct order. I
can't figure that out.
If I change the feed from default to our domain (example.com) I get an
admin priv message. I expected that since I am not an admin. I had
my boss (who is an admin) log in from his computer, but it doesn't
seem to work. Basically I check to see if the user is logged in and
display a message if they are not, and that is all my boss gets even
though it goes through the authentication.
1) What could be causing these issues?
2) What is the best method of achieving the desired groups and email
lists web page but would also take the least amount of learning
curve? I was thinking probably Protocol.
Any help or advice would be greatly appreciated.
I have included my code below:
=====CODE=====
/* Loads the Google Data JavaScript client library */
google.load('gdata', '1.x');
google.setOnLoadCallback(initFunc);
var contactsService;
var scope = 'http://www.google.com/m8/feeds';
function logMeIn() {
var token = google.accounts.user.login(scope);
doGetInfo(scope);
}
/* If this is not called then the cookie is stored for 2 years.
Also, it is retained across browser sessions */
function logMeOut(){
google.accounts.user.logout();
}
function handleInfo(data) {
var response = eval(data.currentTarget.responseText);
alert('Target: ' + response.Target + "\n" +
'Scope: ' + response.Scope + "\n" +
'Secure: ' + response.Secure);
}
function doGetInfo(scope) {
if (google.accounts.user.checkLogin(scope)) {
google.accounts.user.getInfo(handleInfo);
}
}
function setupContactsService() {
contactsService = new google.gdata.contacts.ContactsService('my-
contacts451');
}
function initFunc() {
setupContactsService();
if (google.accounts.user.checkLogin(scope)) {
getMyData();
} else {
var message = "You are not logged in! Click the Login
button to get
your contacts.";
var groupsDiv =
document.getElementById('contact_groups');
groupsDiv.appendChild(document.createTextNode(message));
}
}
function getMyData() {
var output = '';
// The feed URI that is used for retrieving contact groups
var groupFeedUri = 'http://www.google.com/m8/feeds/groups/default/
full';
// The feed URI that is used for retrieving contacts
var contactFeedUri = 'http://www.google.com/m8/feeds/contacts/default/
full';
// callback method to be invoked when getContactGroupFeed() returns
data
var callback = function(result) {
// An array of contact group entries
var entries = result.feed.entry;
var groupsDiv = document.getElementById('contact_groups');
var newGroupList = document.createElement('ul');
newGroupList.id = 'GROUPS';
groupsDiv.appendChild(newGroupList);
// Retrieve the first entry of the contact groups array
for (var g=0; g < entries.length; g++) {
var groupEntry = entries[g];
var groupTitle = groupEntry.getTitle().getText();
var groupId = groupEntry.getId().getValue();
// Query for all the contacts entry with this contact
group
var query = new
google.gdata.contacts.ContactQuery(contactFeedUri);
// Use query parameter to set the group ID
query.setParam('group', groupId);
var groupItem = document.createElement('li');
groupItem.id = 'GROUP_' + groupId;
groupItem.appendChild(document.createTextNode(groupTitle));
newGroupList.appendChild(groupItem);
// callback method to be invoked when getContactFeed()
returns data
var printGroupMembers = function(result) {
var newContactList =
document.createElement('ul');
newContactList.id = 'CONTACT_LIST_' + g;
groupItem.appendChild(newContactList);
// An Array of contact entries
var entries = result.feed.entry;
for (var i = 0; i < entries.length; i++) {
var contactEntry = entries[i];
var emailAddresses =
contactEntry.getEmailAddresses();
for (var j = 0; j <
emailAddresses.length; j++) {
var emailAddress =
emailAddresses[j].getAddress();
var contactItem =
document.createElement('li');
contactItem.id =
'CONTACT_EMAIL_' + j;
contactItem.appendChild(document.createTextNode(emailAddress));
newContactList.appendChild(contactItem);
}
}
}
// Submit the request using the contacts service object
contactsService.getContactFeed(query, printGroupMembers,
handleError);
}
}
if (output){
alert(output);
}
// Error handler
var handleError = function(error) {
alert('Error! ' + error);
}
// Submit the request using the contacts service object
contactsService.getContactGroupFeed(groupFeedUri, callback,
handleError);
}
=====END=CODE=====
--
You received this message because you are subscribed to the Google Groups
"Google Contacts API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-contacts-api?hl=en.