Is it possible to retrieve Image for Contact via Java Contact API ?

64 views
Skip to first unread message

Wojciech Mąka

unread,
Feb 5, 2012, 11:04:50 AM2/5/12
to google-co...@googlegroups.com
Hello,

I've very strange problem with contact api, There is no way for me to retrieve image associated with google contact. 
When executing the code below , I'm getting No Authentication Header Information exception but I'm sure I'm providing correct oauth tokens, as previous 
requests made for retrieving contacts (without images) are successfull. So how it is possible that there is No Authentication Header Information ? (Previously I was calling createLinkQueryRequest() - the exception was No Authentication Header Information  )

GoolgeOAuthParameters oauthParameters = tokenManager.getAuthParameters(email);
OAuthConsumer consumer = new DefaultOAuthConsumer(oauthParameters.getOAuthToken(),oauthParameters.getOAuthTokenSecret);
URL url = new URL(resource);
HttpURLConnection request = (HttpURLConnection)url.openConnection();
consumer.sign(request);
request.connect();
request.getInputStream();

Wojciech Mąka

unread,
Feb 9, 2012, 4:48:22 AM2/9/12
to google-co...@googlegroups.com
Hello again I've really stuck with this, let me be more exact on how I'm trying to accomplish image retrieval from contact profile in google contacts. 
First of all I'm using OAuth 3legged. The scope for authentication is https://www.google.com/feeds/contacts https://docs.google.com/feeds/ 
I'm sure it is correct, and I'm sure I've got correct auth parameters and access token because I CAN RETRIEVE CONTACT ENTRIES, DOCS ENTRIES and everything I want.
After retrieving contact full profile I'm executing code to retrieve image for that contact: 

ContactEntry entry = service.getEntry(contactURL,ContactEntry.class);
Link photoLink = entry.getContactPhotoLink();
if (photoLink !=null && photoLink.getEtag()!=null)
{
    GDataRequest request = service.createLinkQueryRequest(photoLink);
    request.execute();                                                                           // No Authentication header information 
    InputStream stream = req.getResponseStream();                             
}

Execution is broken and exception with message "No Authentication header information" is raised. 

Ok so I'm thinking.. Hmmmmmmmm Hmmmmmmmm Hmmmmmm maybe there is a bug in api. Maybe I should switch to more low level approach...
Let us try with auth post and UrlFetch:

GoolgeOAuthParameters oauthParameters = tokenManager.getAuthParameters(email);
OAuthConsumer consumer = new DefaultOAuthConsumer(oauthParameters.getOAuthToken(),oauthParameters.getOAuthTokenSecret);
URL url = new URL(resource);
HttpURLConnection request = (HttpURLConnection)url.openConnection();
consumer.sign(request);
request.connect();
request.getInputStream(); 

The exeption is now slightly different - the message is 401 unauthorized access but I'm sure the reason is the same. 
So now I would like to ask the people who are managed to fetch image.. How do You succedeed ? 

Api 

gdata-contacts-3.0-1.41.5.jar
gdata-core-1.0-1.41.5.jar
gdata-base-1.0-1.41.5.jar
gdata-client-1.0-1.41.5 jar 


Wojciech Mąka

unread,
Feb 9, 2012, 5:58:08 AM2/9/12
to google-co...@googlegroups.com
OK I do not know How, but finally I recompiled all subprojects , have done  "turn off and turn on again" - like stuff and everything is working !!!!!!!!!!!!!!!!!!! 
Reply all
Reply to author
Forward
0 new messages