Call Google authorization API using Apache HttpClient

I would like to know if you can name the Google API that requires authorization, such as the Google Calendar API, using Apache HttpClient, as well as no Google code or libraries. (and need code for this)

This is the code that I still have, it gets an auth error, What do you use for the user / password?

HttpPost request = new HttpPost("https://www.googleapis.com/calendar/v3/users/me/calendarList/primary?key=mykey"); DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials( new AuthScope(AuthScope.ANY), new UsernamePasswordCredentials(user, password)); HttpResponse response = client.execute(request); 

Mistake:

 "errors": [ { "domain": "global", "reason": "required", "message": "Login Required", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Login Required" 
+1
apache google-calendar google-oauth google-api
source share
1 answer

You do not use the username and password, which must be authenticated, as soon as you have an access token, then you can call something like this.

https://www.googleapis.com/calendar/v3/users/me/calendarList/primary?access_token= {tokenFromAuth}

You can authenticate with Google in any language that is capable of HTTP POST and HTTP GET. Here is my walk, although from the Auth stream to Google http://www.daimto.com/google-3-legged-oauth2-flow/ you will need to create Oauth2 credentials in the Google Developer Console to run. Then you just need to ask the user to access their data and request access.

+1
source

All Articles