Drive API not running? - java

I'm trying to list of all files within Google Drive using Drive API. I've found one API which gives me this list.
When I try to run this API in API explorer it works fine. Give me list of all files
https://www.googleapis.com/drive/v3/files
But when I copy paste url in browser & runs it proving API key, Show me an error.
https://www.googleapis.com/drive/v3/files?key={YOUR_API_KEY}
{
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file."
}
}
I'm pretty new in android. I just want retrieve file list. not search function.

The issue might be your file permission check this documentation for the file permissions -
https://developers.google.com/drive/v3/reference/permissions

Only OAuth 2.0 is supported for Google Drive API.
https://developers.google.com/drive/v3/web/about-auth

Related

tus-java-client + Cloudflare: ProtocolException: unexpected status code (400) while creating upload

I'm attempting to upload a video from a Java (Spring Boot) application to the Cloudflare servers by pulling the video using Spring's RestTemplate and then using the response InputStream to upload the content.
To upload the video content (InputStream), I'm following the docs at Upload Video File and API docs: Video Upload Using TUS
I've used the recommended official tus-java client; But, when I attempt to upload the video I'm getting a
unexpected status code (400) while uploading chunk
When I debug the tus-java-client, I see the underlying error being thrown by the Cloudflare endpoint is:
{
"result": null,
"success": false,
"errors": [
{
"code": 10004,
"message": "Decoding Error"
}
],
"messages": [
{
"code": 10004,
"message": "invalid character '\\x00' looking for beginning of value"
}
]
}
Is there any solution to this so I can successfully upload the video to Cloudflare (stream service)?
I'm using Java 17 and TUS java client version 0.4.5
The full source code of what I'm trying to do along with the steps to replicate this can be checked at this GitHub repo (but please, to let me know if I should paste it here): https://github.com/lealceldeiro/cloudflareuploader#run-the-app
There's an open question in the Cloudflare community here: https://community.cloudflare.com/t/10004-decoding-error-while-uploading-video-to-stream/471107/1

Firebase FCM returning 403 SenderId mismatch PERMISSION_DENIED while trying to push a notification

I'm trying to setup a dev environment for developing with FCM and I'm getting this error.
I'm using the configuration of out-of-box and it is been loaded properly (I've debugged).
I'm working with java 8 and spring 2.2.12 and firebase-admin 7.1.0.
com.google.api.client.http.HttpResponseException: 403 Forbidden
POST https://fcm.googleapis.com/v1/projects/projectt-82004/messages:send
{
"error": {
"code": 403,
"message": "SenderId mismatch",
"status": "PERMISSION_DENIED",
"details": [
{
"#type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode": "SENDER_ID_MISMATCH"
}
]
}
}
What I've tried so far
Create a new project and a new key
There was an old documented error where the services were not activated by default. I've checked the services and all of them are active.
Also, the user appears to have enough privileges.
I've also updated the library to the latest version (it also happened with the previous version)
Am I missing something here?
UPDATE
Same code, later on the following day, without any changes to the code, it started working. So the conclusion was that there was some problem with the service itself.

Why is Google Cloud API trying to connect as an end-user?

I am trying to use the Google Cloud Translate API. I generated a JSON file from a service account and set the GOOGLE_APPLICATION_CREDENTIALS to where the JSON file is saved. I then used it in a program like so:
import com.google.cloud.translate.*;
...
Translate translate = TranslateOptions.getDefaultInstance().getService();
Translation translation = translate.translate(message);
But I get the following error
com.google.cloud.translate.TranslateException: Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the translate.googleapis.com. We recommend that most server applications use service accounts instead. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/
at com.google.cloud.translate.spi.v2.HttpTranslateRpc.translate(HttpTranslateRpc.java:61)
at com.google.cloud.translate.spi.v2.HttpTranslateRpc.translate(HttpTranslateRpc.java:144)
at com.google.cloud.translate.TranslateImpl$4.call(TranslateImpl.java:113)
at com.google.cloud.translate.TranslateImpl$4.call(TranslateImpl.java:110)
at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:89)
at com.google.cloud.RetryHelper.run(RetryHelper.java:74)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:51)
at com.google.cloud.translate.TranslateImpl.translate(TranslateImpl.java:110)
at com.google.cloud.translate.TranslateImpl.translate(TranslateImpl.java:124)
at app.websockets.Messenger.onMessage(Messenger.java:31)
at org.java_websocket.server.WebSocketServer.onWebsocketMessage(WebSocketServer.java:569)
at org.java_websocket.drafts.Draft_6455.processFrame(Draft_6455.java:709)
at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:367)
at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:212)
at org.java_websocket.server.WebSocketServer$WebSocketWorker.run(WebSocketServer.java:925)
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "usageLimits",
"message" : "Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the translate.googleapis.com. We recommend that most server applications use service accounts instead. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/.",
"reason" : "rateLimitExceeded"
} ],
"message" : "Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the translate.googleapis.com. We recommend that most server applications use service accounts instead. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/.",
"status" : "PERMISSION_DENIED"
}
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:1067)
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)
at com.google.cloud.translate.spi.v2.HttpTranslateRpc.translate(HttpTranslateRpc.java:130)
... 13 more
Here is my JSON file:
{
"type": "service_account",
"project_id": "ecstatic-motif-220300",
"private_key_id": "keyid",
"private_key": "somekey",
"client_email": "kokosole#ecstatic-motif-220300.iam.gserviceaccount.com",
"client_id": "100208235593900994013",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/kokosole%40ecstatic-motif-220300.iam.gserviceaccount.com"
}
Can anyone explain what is going on here? How can I fix it? Google Cloud SDK is not even installed.
You are authenticated as a user, while the API expects a service account, seen that you use Client Libraries with the "import com.google.cloud.translate.*;" statement. You may find related detail in the Setting up authentication paragraph on the "Translation API Client Libraries" page.

Execution API Google Apps Script Permissions

Whenever my spreadsheet is edited I want my separate Java code to be notified.
Google Apps Script has Simple Triggers: https://developers.google.com/apps-script/guides/triggers/
I tried out the trigger for onEdit and tested it out by making it that whenever my spreadsheet was edited I'd get an email.
This worked.
Now I'd like to connect the script to my Java code: https://developers.google.com/apps-script/guides/rest/quickstart/java
I went through the quickstart with the sample appscript and it worked. The java file printed out the contents of the root folders of Google Drive.
When I tried to apply the same steps to my onEdit script I get an Permissions Denied error in terminal.
I'm wondering if it's because the simple trigger is bound to the spreadsheet and the Execution API is for unbounded scripts?
How can I connect the onEdit function to Java code?
Here's my error message:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "The caller does not have permission",
"reason" : "forbidden"
} ],
"message" : "The caller does not have permission",
"status" : "PERMISSION_DENIED"
}
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)
at Quickstart.main(Quickstart.java:179)

s3 putObject access denied

I have full permission to my s3 User login:
{
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "*"
}
]
}
There is no group policy attached to this user.
But when I give putObject() command from my java program, I receive Access Denied message.
What can be the issue. As I told my user login has administrator access as well as AmazonS3FullAccess. Thanks for help in advance.
I got the issue resolved.
It was not about firewall or permissions settings as I thought.
I was trying to do putObject on bucket which I should have created before doing this.
Inspite of saying no bucket found AWS gives a message Access Denied, which is wierd.
Hope this helps someone.
You should make sure whether your IP address is allowed or not. For Amazon Services, you can restrict access using IP addresses too. I had the same issue.

Categories

Resources