简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM