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
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
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
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...
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