Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using API KEY in to retrieve activities from google plus is not working

I'm using APIKEY to set up the transport and initialize the connection to retrieve activities from Google Plus.

HttpRequestInitializer initializer =  (HttpRequestInitializer) new  CommonGoogleClientRequestInitializer("GooglePlusAPIKey");  
plusSvc = new Plus(new NetHttpTransport(),  new GsonFactory(), initializer);

It gives me this error:

CommonGoogleClientRequestInitializer cannot be cast to HttpRequestInitializer.

How do I fix this?

like image 547
user1219581 Avatar asked Jan 31 '26 04:01

user1219581


1 Answers

The error message is correct. HttpRequestInitializer and CommonGoogleClientRequestInitializer are not directly related, so the cast is illegal. They are just similar classes in different packages -- you cannot mix-n-match like this.

See docs here: http://javadoc.google-api-java-client.googlecode.com/hg/1.12.0-beta/com/google/api/client/googleapis/services/CommonGoogleClientRequestInitializer.html

The examples here may be easier to follow: https://code.google.com/p/google-api-java-client/wiki/OAuth2

like image 190
Mel Nicholson Avatar answered Feb 02 '26 19:02

Mel Nicholson