tags:

views:

228

answers:

3

Hi,

I am using below code to to create Contact Service and to Validate login Details:

ContactsService obj_ContactService = new ContactsService(""); obj_ContactService.setUserCredentials(userEmail, password);

But even if user enters invalid detail above code does not throw any exception.

User get verified only when i call "Insert" query after adding whole contact details. But in my application i want to notify user immediately after user enters login details.

Thanx

A: 

Hi Pari,

You would have to retrieve the feed (e.g. fetch a list of contacts) to validate that ClientLogin authenticated correctly.

However, you should probably not be using ClientLogin to make these requests, and instead use OAuth or AuthSub, as both are supported by the Contacts API. With OAuth/AuthSub, not only will a user be redirected through Google's secure authentication process, but you won't have to run the insecure overhead of storing the user's username and password in order to run each individual query. Instead, you could just use the authorized token.

If this is an application that needs to run asynchronously (e.g. without users taking an action,) then you should use 2-Legged OAuth.

Good luck!

vicfryzel
How can i do it using Google API Ver2 (For C# ) ?
Preeti Singh
Hi Pari,That is explained in great detail here:http://code.google.com/apis/contacts/docs/1.0/developers_guide_dotnet.html#auth_subThanks,Vic
vicfryzel
A: 

Checkout Accounts APIs and Federated Login for Google Account Users

KMan
+1  A: 

I've played with this a little bit trying to work with, what I think is the V1 stuff, that you were using and this seems to work...

ContactsService cs = new ContactsService("");
cs.setUserCredentials("username", "password");            
string token = cs.QueryAuthenticationToken();

ContactsService cs2 = new ContactsService("");
cs2.SetAuthenticationToken(token);
var results = cs2.Query(new ContactsQuery(ContactsQuery.CreateContactsUri("default")));

It may not be the most correct way to do this (I suspect what vicfryzel says is the way to go) but this may do what you want. The AuthSub stuff appears to be for web apps which is, I'm guessing, why your not using it.

The V2 documents do this a little differently than the way V1 docs do:

RequestSettings rs = new RequestSettings("app", "user", "password");
ContactsRequest cr = new ContactsRequest(rs);

At the moment I'm not sure if you can get a token like you can with the V1 stuff but one of your comments mentioned using "Google API Ver2" so I thought I would include it.

I'm going to keep looking at this since I've been wanting to do something with this myself and I'll edit this answer with anything I find.

drs9222
thanx ...It works nicely.can you help out here:http://stackoverflow.com/questions/2699278/alternate-value-of-feeduri-for-contacts-entry
Preeti Singh