I'm getting the following exception when trying to get data from google calendar Please note that I'm using simple API key :
Exception in thread "main"
com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
{
"code" : 401,
"errors" : [ {
"domain" : "global",
"location" : "Authorization",
"locationType" : "header",
"message" : "Login Required",
"reason" : "required"
} ],
"message" : "Login Required"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1065)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
Here is code :
Calendar calendar = new Calendar.Builder(GoogleNetHttpTransport.newTrustedTransport(),JSON_FACTORY,null).setApplicationName(APPLICATION_NAME)
.setGoogleClientRequestInitializer(new CalendarRequestInitializer(API_KEY))
.build();
List<CalendarListEntry> calendars = calendar.calendarList().list().execute().getItems();// getting exception here
Here is my dependencies related to google :
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-calendar</artifactId>
<version>v3-rev305-1.23.0</version>
</dependency>
API key was create by the following guide :
https://docs.simplecalendar.io/google-api-key/
401 means invalid authorization header.
The access token you're using is either expired or invalid.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization",
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
Try to do the following:
Get a new access token using the long-lived refresh token.
If this fails, direct the user through the OAuth flow, as described in Authorizing requests with OAuth 2.0.
If you are seeing this for a service account, check that you have successfully completed all the steps in the service account page.
You are passing null credentials as the 3rd parameter in Calendar.Builder
That's why you are getting 401.
Related
I am trying to post mappings to a remote server from a spring application. What I found while debugging is that my JSON gets converted to "StubMapping" and this is the place where the code is failing with the following error.
Error creating bean with name 'wiremockConfig' defined in file [C:\Users\Addy\school-impl-api\target\classes\com\test\school\project\wiremock\WiremockConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.test.order.implementation.product.wiremock.WiremockConfig$$EnhancerBySpringCGLIB$$b100848d]: Constructor threw exception; nested exception is com.github.tomakehurst.wiremock.common.JsonException: {
"errors" : [ {
"code" : 10,
"source" : {
"pointer" : "/mappings"
},
"title" : "Error parsing JSON",
"detail" : "Unrecognized field \"mappings\" (class com.github.tomakehurst.wiremock.stubbing.StubMapping), not marked as ignorable"
} ]
}
I got details for posting to a remote standalone server from the following issue (last comment).
https://github.com/tomakehurst/wiremock/issues/1138
My code for posting to the remote server is like this:
WireMock wm = new WireMock("https", "wiremock-poc.apps.pcf.sample.int", 443);
wm.loadMappingsFrom("src/main/resources"); // Root dir contains mappings and __files
This gets loaded when I run the profile local.
Please provide your guidance on how to solve this and move further.
Regards
Update: Sample mapping file.
{
"mappings": [
{
"request": {
"method": "GET",
"urlPathPattern": "/school/admin/rest/users/([0-9]*)?([a-zA-Z0-9_\\-\\=\\?\\.]*)"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"bodyFileName": "./mockResponses/School-getUser.json"
}
}
]
}
After a discussion in chat found out that it's supported to keep each mapping in a separate file.
Here's the source code that is responsible for that: RemoteMappingsLoader#load
I am getting the following error while trying to send request with custom parameter "TOKEN" to elastic search 5.6.3.
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "request [/_search] contains unrecognized parameter: [token]"
}
Is there any configuration that I might need to look into ?
i am using rest api to get an access toke of my user using following link
https://api.pinterest.com/v1/oauth/token?grant_type=authorization_code&client_id=my id&client_secret=my secret&code="+oauthVerifier+
i am getting the response as
{"status": "failure", "code": 3, "host": "devplatform-devapi-prod-4a8937b3", "generated_at": "Tue, 28 Jun 2016 06:06:56 +0000", "message": "Authorization failed.", "data": null}
what shod i do to get my users access token
I'm trying to access 12 dimensions from GA API.
When i did the same with 6-7 parameters, it worked fine.
I searched for the limits & quota but couldn't find anything
regarding this.
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Requested 12 dimensions; only 7 are allowed.",
"reason" : "badRequest"
} ],
"message" : "Requested 12 dimensions; only 7 are allowed."
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:312)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1049)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.tomvogten.analytics.View.readData(View.java:165)
at com.tomvogten.analytics.Downloader.main(Downloader.java:85)
Exception in thread "main" java.lang.NullPointerException
at com.tomvogten.analytics.View.writeData(View.java:191)
at com.tomvogten.analytics.Downloader.main(Downloader.java:86)
Java Result: 1
Unfortunately there is a limitation explicitly stated in the documentation:
"You can supply a maximum of 7 dimensions in any query."
and that is why your request got rejected.
I have the following Org Units hierarchy:
..
../Unit1
..../SubUnit
../Unit2
I'm trying to move SubUnit from Unit1 to Unit2 with code like this:
List<String> list = new ArrayList<String>();
list.add("Unit1");
list.add("SubUnit");
OrgUnit orgUnit = directoryService.orgunits().get("my_customer", list).execute();
orgUnit.setParentOrgUnitPath("/Unit2");
directoryService.orgunits().update("my_customer", list, orgUnit ).execute();
but it always fails with:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
"code" : 404,
"errors" : [ {
"domain" : "global",
"message" : "Parent Org unit not found",
"reason" : "notFound"
} ],
"message" : "Parent Org unit not found"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
The error message is quite clear, but the ParentOrgUnit exists at the moment of the call and its path is provided correctly. I tried many times with different units with same result using:
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-admin-directory</artifactId>
<version>directory_v1-rev53-1.20.0</version>
</dependency>
Any help?
The only question I've found about but it doesn't help:
Directory API moving an organization unit using google api for java to another organization unit