How to Import Google Contacts Info

margret

Well-Known Member
Licensed User
Longtime User
Hello,

I really need to be able to read/import google contacts into B4A. This is in an app I am writing. The user can provide the authorization needed. I have looked for days and can find nothing that gives what I am looking for. I don't care about the email/messages, etc. Just the contact info and everything that in stored in the info record. Can this be done in B4A? Please any info would be great.

Thanks,

Margret
 

margret

Well-Known Member
Licensed User
Longtime User
Import Contacts

Have you tried with Contacts?
Basic4android - Phone

Hello Erel,

I am not talking about local contacts on the device. I need to import the contacts list from their PC based gmail account. I can't find anything on this and a lot of them don't want to re-enter their gmail contacts into my APP. If you can help it would be great.

Margret
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Import contacts

In most cases Android does it automatically. Once you set the device Gmail account, it imports all the contacts from Gmail to the internal contacts.

Erel, this device does not have gmail. This is why I posted the question in the first place. It has some custom contacts app with just a name and no intents. Please, if you can help with a way to import from a pc account, this is what I need.

Margret
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Over My Head

Have a look at: Google Contacts Data API - Google Code
I havent read it yet myself but I am sure this is what you need!
EDIT:
Also look at: Developer's Guide - Google Contacts Data API - Google Code
There is also Java code. You might be able to roll your own library.

Thank You for your help. I did look at it and it's above me. It's all java and Eclipse. That's why I am using B4A. I guess B4A has no options for us on this. It would be a major undertaking I believe to get it all working unless one of you Guys with the knowledge would jump in. So until then I am stuck.
I really need this but I have no clue.

Thanks,

Margret
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Import Contacts

I think modifying Erel's Dropbox example in b4a should help.
It uses OAuth as well (I am not sure of OAuth 2.0)
Hopefully it should just be a matter of changing the address URLs and parsing the response.
I will try later today (if I get the time :( ).

Thank you for anything you can do!


Margret
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I am sorry I havent done much. But I have managed to get my contacts out using some examples.
Basically if you go to: OAuth Playground
it will walk you through the process of getting Authorised and getting the contacts.
It works but the OAuth signature method it uses is RSA-SHA1. I do not think Erel's library supports this. It supports HMAC-SHA1.
Even though Google's OAuth also supports HMAC-SHA1 I have not figured out where to get the consumer_key and consumer_secret from. If you manage to get those then this should be fairly easy.
I recommend you go to the OAuth playground (linked above) and check out the cool stuff you can do there. :)
EDIT:
Looking at more links (http://code.google.com/apis/accounts/docs/MobileApps.html) it seems that RSA-SHA1 can only be used by web apps that have a registered domain. Installed apps have to use HMAC-SHA1 and use a WebView to sign in, use the cookie manager to get the authentication.
This looks more complicated than I initially thought.
 
Last edited:
Upvote 0

ozgureffe

Member
Licensed User
Longtime User
Hi Margret,

I think at this time it can be done only with the help of Http Lib.

I made a search and found an opensource webservice named Open Inviter - Free Import contacts and integrate with CMS like PunBB, PhpBB, PHPMELODY and many more.

They provide lots of contact importing services including gmail...

I downloaded and attached their gmail plugin in written in PHP to get contact list..

If you look for a way to translate this PHP code to use it with b4a with the help of Http Lib, maybe this can solve your problem.
 

Attachments

  • gmail.plg.txt
    5.8 KB · Views: 265
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Google Contacts

Hi Margret,

I think at this time it can be done only with the help of Http Lib.

I made a search and found an opensource webservice named Open Inviter - Free Import contacts and integrate with CMS like PunBB, PhpBB, PHPMELODY and many more.

They provide lots of contact importing services including gmail...

I downloaded and attached their gmail plugin in written in PHP to get contact list..

If you look for a way to translate this PHP code to use it with b4a with the help of Http Lib, maybe this can solve your problem.

Thanks for your lead on this. I looked through it and I don't think it will work. These are scripts for running on a web server. I did send them an email just to see if I missed something. I explained what I am doing and what I am working with. We will see what they say.

Thanks,

Margret
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Hi margret,
Dont know if you have up with an alternative solution already, because I am just too slow!
Anyway, I am just 1 step closer but I do not have experience with the WebView so I have not been able to complete this yet.
Basically what we want is pretty much on this page: Using OAuth 2.0 to Access Google APIs - Authentication and Authorization for Google APIs - Google Code

Register your app here: https://code.google.com/apis/console under the API access tab. You will get a client id that you will need.

In a webview open this URL.
B4X:
mykey = "https://accounts.google.com/o/oauth2/auth?" & _
         "client_id=xxx.apps.googleusercontent.com&" & _
           "redirect_uri=urn:ietf:wg:oauth:2.0:oob&" & _
           "scope=https://www.google.com/m8/feeds/&" & _
           "response_type=code"
   
   
   w1.LoadUrl(mykey)

Then sign in with your account.

At the end you will get an Access Token.
This is all we need. After that if you Load (with your access token):
B4X:
https://www.google.com/m8/feeds/contacts/default/full?access_token=1/fFAGRNJru1FTz70BzhT3Zg

You should have your contacts in response. Unfortunately I have not been able to programmatically get the Access token out from the webview. (Apparently the token is set as the 'Title' of the webview).

Someone like warwound or Erel can help in this regard.
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Hi margret,
Dont know if you have up with an alternative solution already, because I am just too slow!

Hello thedesolatesoul,

I have not come up with anything yet. I really need to but I have been looking and reading but nothing working yet. I am o.k. with B4A but I'am having a hard time with the token/access methods used with Oauth. I will keep trying until you experts show me how it's done. Thank all of you for your help and pointers on this. At least when it's all done, it will be here for others too.

Thanks,

Margret
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Okay I have also managed to grab the Access Token from the webview's title using warwound's JSInterface library.
Something was wrong with my last request for contacts, i will check that later when i get back from work.

EDIT:
I have read a bit more about it and I missed out one more step.
Right now I only have the Authorization code. I need to make another request to get the Access token.
For the first step only, you need the webview, the rest can probably be done with HttpUtils.
 
Last edited:
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Okay, here it is.
This project will retrieve the google contacts for you. However, it is returned in an XML file and I havent parsed that.
This may come in handy for other google services as well (Google+, Calendar, Tasks, Docs) I hope so. But I dont think it does GMail.

First register your app: https://code.google.com/apis/console

Put the client_id and client_secret in the code.

It starts with the authentication in a webview. When the user allows access in the webview it returns an Authentication code.
You can hide the webview after this if you want.

I used HttpUtils to get the AccessToken and RefreshToken from the authentication code by sending another request. These AccessTokens are valid for 1 hour, if you need more time then use the RefreshToken to get another AccessToken.

Then use the AccessToken with Google Data API commands. In this case the Contacts API to return all contacts.

Unrelated:
Another useful site I found today is: API Kitchen to test HTTP requests etc.
 

Attachments

  • GoogleContacts.zip
    8.1 KB · Views: 255
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
This is Great

Okay, here it is.
This project will retrieve the google contacts for you. However, it is returned in an XML file and I havent parsed that.

Hello thedesolatesoul,

I just logged on and saw this and I will go through it tomorrow! You are great!! This is why you guys are the experts...!!!!!

Thank, thank, thank You,

Margret
 
Upvote 0
Top