How to get userID and password ?

118 views
Skip to first unread message

Raj

unread,
Dec 23, 2009, 3:22:40 AM12/23/09
to Google Contacts API
Hello All,

I am using google contacts api and I am able to retrieve the contacts
from gmail.

But for this I need to hardcode the credentials "userid" and
"password" in following method.

ContactsService myService = new ContactsService("exampleCo-
exampleApp-1");
myService.setUserCredentials("l...@gmail.com", "password");


from where can I get the userid and password so that I can user that
info and need not to hardcode the values?

thanks in advance.

RAJESH

Sanket Shah

unread,
Dec 23, 2009, 3:42:29 AM12/23/09
to Google Contacts API
Make a wrapper function around this call and pass the values through
this.

An example would be:

public static ArrayList GetContacts(string userName, string password)
{
ArrayList contactsList = new ArrayList();

ContactsService myService = new ContactsService("YourAppName");
myService.setUserCredentials(userName, password)
.....
Your rest of the code goes here...
.....

return contactsList;
}

An example to use the above function will be:
(Am using .NET notation)

protected void ShowContacts_Click(object o, EventArgs e)
{
ArrayList contactsList = ContactsRetriever.GetContacts
(txtUserName.Text, txtPassword.Text);
}


I guess this will help you out.

-Sanket

Raj

unread,
Dec 23, 2009, 4:45:12 AM12/23/09
to Google Contacts API
Thanks Sanket,

But I am using Java and I need to get it to set credentials to set in
the above method.

Can I get it anyway by using session token ?

I am using following URL : http://code.google.com/apis/contacts/docs/2.0/developers_guide_java.html#auth_sub

Sanket Shah

unread,
Dec 23, 2009, 5:01:34 AM12/23/09
to Google Contacts API
Hi Raj,

You can surely get the token using AuthSub API.

Although am not much in deep into AuthSub, thats the best I can
suggest.

I guess google team will be able to help more. Expect reply from them
this night (considering IST timeline).

-Sanket

> I am using following URL :http://code.google.com/apis/contacts/docs/2.0/developers_guide_java.h...

Message has been deleted

Raj

unread,
Dec 23, 2009, 6:43:34 AM12/23/09
to Google Contacts API
Thanks Sanket,

Here is code what I am trying to work with for the reference :

In JSP I am putting this :

<a href="https://www.google.com/accounts/AuthsubRequest?next=http://
xx.xxx.xxx.xx:8080/GContacts/GoogleTest&scope=http://www.google.com/
calendar/feeds/http://www.google.com/m8/feeds/
contacts&secure=0&session=1">

which after authentication redirect me to the :http://xx.xx.xx.xx:
8080/GContacts/GoogleTest

And here in the servlet below is the code where I want the userid and
password comes from authsub :

protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{

try
{
String token=AuthSubUtil.getTokenFromReply
(request.getQueryString());
String sessionToken =
AuthSubUtil.exchangeForSessionToken("https","www.google.com",token,
null);
ContactsService contactsService = new
ContactsService("GoogleTest");
contactsService.setAuthSubToken(sessionToken,
null);

contactsService.setUserCredentials
("x...@gmail.com", "xxxxxxx#");
GoogleTest.printDateMinQueryResults
(contactsService);
}
catch (AuthenticationException e)
{
e.printStackTrace();
}

}

}

thanks in advance

Julian (Google)

unread,
Dec 27, 2009, 7:22:17 AM12/27/09
to Google Contacts API
This group has been moved to the Google Apps API Help Forum
Please use the new forum: http://www.google.com/support/forum/p/apps-apis?hl=en

--Julian

Reply all
Reply to author
Forward
0 new messages