views:

275

answers:

2

Hi all,

In my android application, I would like to retrieve the birthday field from google.com/contacts, as this field isn't synchronised in the android contacts application. How can I have a read access to google contacts ?

I saw the Google contacts APIs, did I have to use it ? which one ? the Portable version ?

Or is there a simple way to read these contacts, as Android does when there is a synchronisation ?

Thanks in advance

+1  A: 

It should be possible since android 2.0 using AccountManager.

There are no tutorials nor samples, I don't have access to any >=2.0 device to try it out.

See http://code.google.com/p/android/issues/detail?id=1073#c28

As I understand you should be able to getAuthToken fo Google account and pass it in Authorization header as here Authorization: GoogleLogin auth=yourAuthToken

skyman
Thx but my device is on 1.5
kosokund
+2  A: 

There used to be a hack before the AccountManager was reased, I started a thread about a year ago on the android developer group, but it has been removed. There was an undocumented method that you had to access through reflection. I can't seem to find it anywhere now, like google has deleted the thread or something. I found something similar below, but it's not the one I had working.

http://donpark.org/blog/2009/01/24/android-client-side-oauth

At worst case, most devices that are out now, should eventual get 2.1. So you could just make them login then validate and get the auth key from google, and if they are on 2.1 use the AccountManager and don't bother them with the credentials. something like below

WebRequest req = HttpWebRequest.Create(
@"https://www.google.com/accounts/ClientLogin?    accountType=GOOGLE&[email protected]&Passwd=pass&service=gbase&source=sadboy");
WebResponse resp = req.GetResponse();

string all;
using (StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()))
    all = sr.ReadToEnd().Trim();

int auth = all.IndexOf("auth=");
string auth = all.Substring(auth, all.Length - auth);

http://developer.android.com/intl/zh-TW/resources/dashboard/platform-versions.html

sadboy