Listing Team Drive Files: Error 403 insufficientPermissions - google-api

I'm trying to access the files of my Team Drive, but I got a 403 error, while I can access to my files of my normal Google Drive.
Is it necessary to add a specific permission on the OAuth key ?
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
Drive service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
.setApplicationName(APPLICATION_NAME)
.build();
String pageToken = null;
do {
TeamDriveList result = service.teamdrives().list()
.setFields("nextPageToken, files(id, name)")
.setUseDomainAdminAccess(true)
.setPageToken(pageToken)
.execute();
for (TeamDrive file : result.getTeamDrives()) {
System.out.printf("Found file: %s (%s)\n",
file.getName(), file.getId());
}
pageToken = result.getNextPageToken();
} while (pageToken != null);
And the response :
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Insufficient Permission",
"reason" : "insufficientPermissions"
} ],
"message" : "Insufficient Permission"
}

Related

Gmail API Service Account Issue

I am trying to send email using gmail api service account from spring boot api.
GoogleCredentials credentials = ServiceAccountCredentials.fromStream(inputStream)
.createScoped(Collections.singletonList(StorageScopes.DEVSTORAGE_FULL_CONTROL));
credentials = credentials.createScoped(SCOPES);
credentials.refresh();
AccessToken refreshToken = credentials.refreshAccessToken();
OAuth2Credentials credentialsAccess = OAuth2Credentials.create(refreshToken);
LOGGER.info("refresh token {}", credentials.refreshAccessToken().getTokenValue());
LOGGER.info("refresh token {}", credentialsAccess.getAccessToken().getTokenValue());
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);
Gmail service = new Gmail.Builder(new NetHttpTransport(), JacksonFactory.getDefaultInstance(),
requestInitializer).setApplicationName(APPLICATION_NAME).build();
Users a = service.users();
sendMessage(service, "me", mimeMessage);
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Precondition check failed.",
"reason" : "failedPrecondition"
} ],
"message" : "Precondition check failed.",
"status" : "FAILED_PRECONDITION"
}

Elasticsearch, which path for elasticsearch.keystore is used?

I'm trying to understand why I get 401.
Steps taken:
created a elasticsearch.keystore
add the bootstrap.password successfully, with cat ~/.elk.secret | /opt/elasticsearch/bin/elasticsearch-keystore add -x 'bootstrap.password'
Since I've multiple instances running, I move it in the new conf directory
but now I get 401:
curl -X GET 'https://elastic:myFancyPass#myServer:9200/_cluster/health?pretty' -k
{
"error" : {
"root_cause" : [
{
"type" : "security_exception",
"reason" : "unable to authenticate user [elastic] for REST request [/_cluster/health?pretty]",
"header" : {
"WWW-Authenticate" : [
"Bearer realm=\"security\"",
"ApiKey",
"Basic realm=\"security\" charset=\"UTF-8\""
]
}
}
],
"type" : "security_exception",
"reason" : "unable to authenticate user [elastic] for REST request [/_cluster/health?pretty]",
"header" : {
"WWW-Authenticate" : [
"Bearer realm=\"security\"",
"ApiKey",
"Basic realm=\"security\" charset=\"UTF-8\""
]
}
},
"status" : 401
}
My understanding is that this error can be caused by two things:
wrong password (which I doubt it's my case)
wrong elasticsearch.file
How do I find which elasticsearch.keystore it is loading?
Running rootLogger.level = debug didn't help. I feel it would be great getting a confirmation such as /opt/elasticsearch/instance2/conf/elasticsearch.keystore

Elasticsearch Java API access source when Exception is thrown

I am learning the Java RestHighLevelClient but I can't find the answer to this question.
When you submit a REST request to something where a document is not found you will see something like this:
$ curl localhost:9200/customer/_doc/1?pretty
{
"error" : {
"root_cause" : [
{
"type" : "index_not_found_exception",
"reason" : "no such index [customer]",
"resource.type" : "index_expression",
"resource.id" : "customer",
"index_uuid" : "_na_",
"index" : "customer"
}
],
"type" : "index_not_found_exception",
"reason" : "no such index [customer]",
"resource.type" : "index_expression",
"resource.id" : "customer",
"index_uuid" : "_na_",
"index" : "customer"
},
"status" : 404
}
However in the Java client you code something like this:
GetRequest request = new GetRequest(INDEX, ROOT);
GetResponse response = null;
try {
response = client.get(request, RequestOptions.DEFAULT);
} catch (IOException ioe) {
// do something with the IOException
} catch (ElasticsearchException ese) {
// where is the response source?
}
So if the document is not found, you get the ElasticsearchException in which case the local variable response is null. So where do you get
the source document that was present at the low level? (Preferably as a Map).
You can get to the source of the response at the low level via the suppressesed exceptions in the ElasticsearchException.
Throwable[] suppressed = ese.getSuppressed();
if (suppressed.length > 0 && suppressed[0] instanceof ResponseException) {
ResponseException re = (ResponseException) suppressed[0];
Response response = re.getResponse();
}

Multipart file (not given condition).Error-400(bad request)

My rest api is.
#PutMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUEpath="/{referenceNumber}")
public void updateCard(#RequestHeader(value = tenantId) String theTenantId,
#PathVariable String referenceNumber,#RequestParam(value = "card")MultipartFile multipartFile,HttpServletRequest request)
I need to check the condition like without browsing the file.
my input format is
Headers :
tenantId : ***
Body : selecting "formdata" (Postman), "multipart-formdata" (AdvancedRestClient)
card : without browsing file
Then i am getting the following error in Postman.
{
"timestamp": 1549351840816,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.web.multipart.support.MissingServletRequestPartException",
"message": "Required request part 'card' is not present",
"path": "/app-1.5.0/1.5/references/34a236d7-9305-402f-959d-8c83d5ededbb"
}
If i try in the AdvancedRest client with same input
I am getting the different error.
{
"timestamp": 1549352119229,
"status": 415,
"error": "Unsupported Media Type",
"exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
"message": "Content type 'null' not supported",
"path": "/app-1.5.0/1.5/references/34a236d7-9305-402f-959d-8c83d5ededbb"
}
Is there any reason for different outputs and can i check the api without
browsing file.
#PutMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUEpath="/{referenceNumber}")
public void updateCard(#RequestHeader(value = tenantId) String theTenantId,
#PathVariable String referenceNumber,#RequestPart(required = false,value = "card")MultipartFile multipartFile,HttpServletRequest request){
}
User #RequestPart instead of #RequestParam

Google calendar api 3 invalid credentials error

I'm trying to access calendar details but I seem to get a invalid credentials error.
I access the following url: "https://www.googleapis.com/calendar/v3/calendars/{google_id}/events"
like this :
DefaultHttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url_);
get.addHeader("Authorization","OAuth" + auth_token);
try {
HttpResponse response = client.execute(get);
What extra headers should I put there? I'm accessing it from an android application. If it matters I got my auth_token by an activity started with AccountManager.newChooseAccountIntent().
I'm getting the following json:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
There should be a space between OAuth and the token in your header.

Resources