Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Getting Contacts From Gmail

Posted on 2009-05-10
8
Medium Priority
?
307 Views
Last Modified: 2013-12-20
Hi Experts, i am using Ray's Tag for fetching Contacts From my Gmail Account. Althouh it fetched correctly and showed in a cfdump var which have structs and arrays inside that. so i am really confused how to use that.

i will attached the list here how the results are coing. just show me a way how can i use them in real code like:

display a checkbox against each email address.

the code is below:


<cfapplication name="gContacts">
 
<cfset url.reinit = 1>	
<cfif not structKeyExists(application, "gContacts") or structKeyExists(url, "reinit")>
	<cfset application.gContacts = createObject("component", "#request.cfcPath#.GoogleContacts").init("cool@gmail.com","cool")>
</cfif>
 
<cfset contacts = application.gContacts.getContacts()>
<cfdump var="#contacts#" label="Contacts" expand="true">	
 
the file is attached.

Open in new window

coool.JPG
0
Comment
  • 4
  • 3
8 Comments
 
LVL 12

Expert Comment

by:geowrian
ID: 24347623
You have an array with structures in it. Each structure has elements...some are text/numbers and others are arrays or more structures. Thinking along those lines, you could access items like this:

<cfoutput>
Record 1:<br>
Email Address 1: #Contacts.Contacts[1].EMAIL.Contacts[1].ADDRESS#<br>
ID: #Contacts.Contacts[1].ID#
</cfoutput>

Sorry if that's not entirely correct...I can't the entire structure and it is large and multi-layered. If you follow that logic, you should be able to narrow down the exact way to access each item.

You will probably need to loop through each array, so it gets mroe complicated but take it one stap at a time and it's not too bad.
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 24347633
i just only want to fetch the email address that's all. will you approach work i will try and post it <input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">
0
 
LVL 12

Expert Comment

by:geowrian
ID: 24347656
It should work fine (barring anything I couldn't see in the image or a brain fart). To get all the email addresses per user, you will have to use an outer and an inner loop. First cfloop the Contacts.Contacts to get the email addresses for each user. Within that loop, cfloop the inner Contacts structure to get each email address for the user.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 24347670
i get error:<input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">
Record 1:
Email Address 1:
 
The web site you are accessing has experienced an unexpected error.
Please contact the website administrator.
 
The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request
Element EMAIL.CONTACTS is undefined in a CFML structure referenced as part of an expression.
 
The error occurred in C:\Inetpub\wwwroot\ibestcity\google.cfm: line 16
 
14 : <cfoutput>
15 : Record 1:<br>
16 : Email Address 1: #Contacts.Contacts[1].EMAIL.Contacts[1].ADDRESS#<br>
17 : ID: #Contacts.Contacts[1].ID#
18 : </cfoutput>

Open in new window

0
 
LVL 12

Expert Comment

by:geowrian
ID: 24347802
Hmm....maybe I missed a structure. I would suggest avoiding having the same name used over and over whenever possible as it creates confusion. Try the code below. If that doesn't work, just cfdump each outer element until you get the exact syntax to reach the email field.
<cfoutput>
Record 1:<br>
Email Address 1: #Contacts.Contacts[1].EMAIL[1].ADDRESS#<br>
ID: #Contacts.Contacts[1].ID#
</cfoutput>

Open in new window

0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 24347829
cool, it works but it outputs only one record, i have 25 contacts in my gmail it shows only single one, i did something like this:


<input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">
<cfset contacts = application.gContacts.getContacts()>
<cfloop query="contacts">
<cfoutput>
#Contacts.Contacts[1].EMAIL[1].ADDRESS#<br>
</cfoutput>
</cfloop>
 
it errors out as:
 
Attribute validation error for tag cfloop.  
The value of the attribute query, which is currently contacts, is invalid.  
  
The error occurred in C:\Inetpub\wwwroot\ibestcity\google.cfm: line 13
 
11 : 
12 : <cfset contacts = application.gContacts.getContacts()>
13 : <cfloop query="contacts">
14 : <cfoutput>
15 : #Contacts.Contacts[1].EMAIL[1].ADDRESS#<br>
 
 

Open in new window

0
 
LVL 12

Accepted Solution

by:
geowrian earned 1400 total points
ID: 24347858
Right. That was just to show how it's done. You need to loop over the array. Your code is trying to loop over a query. basically, you need to loop over Contacts.Contacts. Within that, you need to loop over EMAIL. Below is Coldfusion MX code to do this. Coldfusion 8 supports an array option for cfloop but I don't know what version you are using so I didn't use it.

This was made off-hand, so don;t be surprised if there's a typo somewhere.
<cfoutput>
  <cfloop index="i" from="1" to="#ArrayLen(Contacts.Contacts)#">
    <cfloop index="j" from="1" to="#ArrayLen(Contacts.Contacts[i].EMAIL)#">
      <div>Email: #Contacts.Contacts[i].EMAIL[j].ADDRESS#</div>
    </cfloop>
  </cfloop>
</cfoutput>

Open in new window

0
 
LVL 63

Assisted Solution

by:Zvonko
Zvonko earned 600 total points
ID: 24347863
Here the checkboxes:
<form>
<cfoutput>
<cfloop array="#contacts.contacts#" index="contact" >
  <cfif contact.title EQ "" >
    <cfset contact.title = contact.email[1].address >
  </cfif>
  <input type="checkbox" name="contact_id#contact.id#" id="contact_id#contact.id#" value="#contact.email[1].address#" > <label for="contact_id#contact.id#" >#contact.title#</label> <br>
</cfloop>
</cfoutput>
<input type="submit" >
</form>

Open in new window

0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question