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.
Related
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.
I am using IBM Bluemix Rest APIs for Push Notifcation with Spring Boot 1.5.6.RELEASE and Java 1.8. I am using RestTemplate for invoking the below APIs from Java Code. I am sending push notifications to ios devices registered to APNS (Apple Push Notification service).
I am binding the push notification service to my java app on BlueMix and getting the url, clientSecret, and appSecret from VCAP_SERVICES.
I am noticing a weird behavior and was wondering if anyone else has also experienced the same.
Please refer to the below steps:
I am registering a device using "registerDevice" POST API. The endpoint for which is "http://imfpush.xxxxxxxx.xxxx.bluemix.net/imfpush/v1/apps/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/devices".
I verify that the device is registered successfully using "getDevices" GET API. The endpoint for which is "http://imfpush.xxxxxxxx.xxxx.bluemix.net/imfpush/v1/apps/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/devices".
I then send a push noification using "sendMessage" POST API. The endpoint for which is "http://imfpush.xxxxxxxx.xxxx.bluemix.net/imfpush/v1/apps/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/messages".
The weird behavior I am noticing is after invoking the sendMessage POST API, the device which I registered in step 1 is no longer registered. After step3 above if I go back to step 2 and invoke the "getDevices" API again, the device is no longer registered. It returns below response:
{
"pageInfo": {
"totalCount": 0,
"count": 0
},
"devices": []
}
Is this a bug in "sendMessage" POST API?
Please help
Thanks in advance
The de-registration of the device is due to an invalid or inactive token for that registered device. Bluemix is deleting the registration because APNs/GCM is responding that the device's token is invalid when a push is attempted against it. Can you please make sure to configure valid credentials for APNS/GCM.. Follow the steps from the doc to Obtain your notification provider credentials
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)
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
I am testing this with postmaster tool but no results. coming from the PayPal and url is https://api.sandbox.paypal.com/v1/oauth2/token. can any one give solution. For me getting this error : {
"error": "invalid_client",
"error_description": "Invalid client credentials"
}
Be sure your client and secret are getting passed in the Authorization header, essentially as user/password in basic auth.
This page details the process pretty well.
https://developer.paypal.com/webapps/developer/docs/integration/direct/make-your-first-call/