Gmail API watch request not working properly - gmail-api

There are many post on this same topic but still there is no exact solution to solve this issue.
even in the google API below link, there is a option to test the API
https://developers.google.com/gmail/api/v1/reference/users/watch
This API throws a error like Invalid Topic Name does not match but I have created the topic in the pub sub and I have published the message on it, that topic works fine but then also I am receiving below error. I am receiving 400 error
{ "error": {"errors": [{
"domain": "global",
"reason": "invalidArgument",
"message": "Invalid topicName does not match projects/google.com:apisexplorerconsole/topics/*" } ],"code": 400,"message":"Invalid topicName does not match projects/google.com:apisexplorerconsole/topics/*" }}
I have tried to call this API in client side, like below
gapi.client.gmail.users.watch({
'userId': 'me',
"topicName": "projects/fast-metric-178608/topics/Test"
}).then(function (response) {
console.log(response)
});
Below is output , i am receiving 403 error
{ "error": { "errors": [{
"domain": "global",
"reason": "forbidden",
"message": "Error sending test message to Cloud PubSub projects/fast-metric-178608/topics/Test : User not authorized to perform this action."} ],"code": 403, "message": "Error sending test message to Cloud PubSub projects/fast-metric-178608/topics/Test : User not authorized to perform this action." }}

https://console.cloud.google.com/cloudpubsub/topicList
select your topic and
set your topic PERMISSIONS allUser and Select a role Pub/Sub Admin

Related

Failed to Fetch - Cors Error - When Fetching with Authorization Header - On Postman working OK

Hi everybody i'm trying to solve some issue.
I need to get some data, with my credentials.
If i do it on POSTMAN , with Auth Basic Authorization, i get the data, but when i try it on my code, which runs on the browser, i get on the console "TypeError: Failed to fetch" and on network i get this status "CORS error".
This is the code:
fetch(
'https://content-us-8.content-cms.com/api/f8d92c5b-2ec6-46ee-8e22-cd2d9a556473/authoring/v1/content/views/by-type?id=5030aaad-9bf6-45db-9a3e-5cc7cd190103',
{
headers: {
Authorization: 'Basic ' + base64.encode(userName + ':' + password)
},
withCredentials: true
}
)
.then((el) => el.json())
.then((el) => console.log(el))
.catch((err) => console.log(err))
.finally((el) => {
console.log('FINALLY');
console.log(el);
});
If i do the call without headers i get this error:
{
"requestId": "807bd27d2b28962b9d2834458e926499",
"service": "prod-infra-api-dispatcher",
"version": "0.0.1883",
"description": "Acoustic Content, API Dispatcher Component",
"errors": [
{
"name": "AccessControlError",
"message": "The user 'undefined' tried to perform GET /content/views/by-type with tenant 'f8d92c5b-2ec6-46ee-8e22-cd2d9a556473'. Access to the service was denied because the user roles 'anonymous' do not match the accepted roles 'admin,manager,editor,viewer'. Verify that the user has the correct role assigned.",
"locale": "en",
"parameters": {
"statusCode": 403,
"method": "GET",
"path": "/content/views/by-type",
"roles": [
"anonymous"
],
"requiredRoles": [
"admin",
"manager",
"editor",
"viewer"
],
"timestamp": 1650811022658
},
"timestamp": "Sun, 24 Apr 2022 14:37:02 GMT"
}
],
"timestamp": "Sun, 24 Apr 2022 14:37:02 GMT",
"message": "The user 'undefined' tried to perform GET /content/views/by-type with tenant 'f8d92c5b-2ec6-46ee-8e22-cd2d9a556473'. Access to the service was denied because the user roles 'anonymous' do not match the accepted roles 'admin,manager,editor,viewer'. Verify that the user has the correct role assigned."
}
I understand this error occurs because i'm not setting credentials... but i've tried multiple ways to achieve this without success.
The browser makes a cross-origin GET request with Authorization header only if the preceding preflight request succeeds. But as you can try out with curl:
>curl -I -X OPTIONS -H "Access-Control-Request-Headers:Authorization"
-H "Origin:http://localhost"
https://content-us-8.content-cms.com/api/...
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: http://localhost
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET,OPTIONS
Access-Control-Allow-Headers: accept,accept-language,content-language,pragma,cache-control,x-xsrf-token,x-acoustic-region,x-acoustic-auth-source,x-ibm-dx-tenant-id,x-cms-user-auth,x-ibm-dx-user-auth
Access-Control-Expose-Headers: cache-control,content-language,content-type,expires,last-modified,pragma,x-ibm-dx-request-id,x-response-time
the Authorization header is not in the list of allowed headers. In other words: The service does not allow basic authentication in cross-origin requests.
If you cannot influence the backend on content-cms.com so that Authorization becomes an allowed header, the only option is to tunnel the request through your own backend server. Or are you programming "server-less"?

Alexa skill is giving 'There was a problem with the requested skill's response', can we change this message to custom message?

I am new to Alexa skill, and I am developing an Alexa skill, in my case there are scenario when I don't want to wait for http response to back and if my lambda timeouts due to delay in response from Http can I give a custom message in place of 'There was a problem with the requested skill's response'. My code is :
'ProtectArmIntent': function() {
if(checkAccessToken(this.event.session.user.accessToken)){
var data = {
mode: HUB_MODE.ARM,
regId: "null"
}
callAPI("post", API_COMMANDS.HUB_MODE, data, this.event.session.user.accessToken)
.then((body) => {
if(body.response.status === "SUCCESS"){
this.emit(':tell', messages.ARM.SUCCESSFUL);
} else {
this.emit(':tell', messages.ARM.FAILED);
}
})
.catch((err) => {
this.emit('SessionEndedRequest');
//errorHandler.call(this, err, messages.ARM.FAILED);
});
} else {
this.emit('LinkAccount');
}
},
and alexa simulator request:
"request": {
"type": "SessionEndedRequest",
"requestId": "amzn1.echo-api.request.67e1612e-f8a4-43f5-ab28-175ba7d7941f",
"timestamp": "2019-11-13T21:13:11Z",
"locale": "en-GB",
"reason": "ERROR",
"error": {
"type": "INVALID_RESPONSE",
"message": "An exception occurred while dispatching the request to the skill."
}
}
I know the issue is because lambda timeout as delay in the HTTP response, so can I give some customize message like Your command is accepted and it will be executed in some time.
Please please help, Thanks in advance
Making your own timer function might help. Set your timer lower than the lambda timeout and send your response at the end of the timer which will of course not lead to a lambda timeout error.This answer might help.

Delete label request returning 400 even though label exists

I am having issues with the label delete Gmail API.
No matter what label I submit, I get the error response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "Invalid delete request"
}
],
"code": 400,
"message": "Invalid delete request"
}
}
To reproduce, I first make the request:
POST https://www.googleapis.com/gmail/v1/users/me/labels
{"labelListVisibility":"labelShow","messageListVisibility":"show","name":"C2"}
Which succeeds and then immediately after I send:
DELETE https://www.googleapis.com/gmail/v1/users/me/labels/C2
Which produces the aforementioned error. I can see the label in my gmail inbox so I know it is successfully created and present. Any advice on what I am doing wrong?
You cannot delete a label by name, but must do so by its ID
See here. The Id of the label is contained in the response of the
POST https://www.googleapis.com/gmail/v1/users/me/labels
request:
{
"id": "Label_3",
"name": "C1",
"messageListVisibility": "show",
"labelListVisibility": "labelShow"
}
You can also list all you labels to retrieve their IDs.
The delete request should look something like:
DELETE https://www.googleapis.com/gmail/v1/users/me/labels/Label_3
whereby Label_3 should be replaced by your label ID.

How to get access token programatically for GCP Compute API

I need some help for access tokens in GCP. I am using Java as program language and I tried different approaches like:
https://cloud.google.com/iap/docs/authentication-howto
and https://developers.google.com/identity/protocols/OAuth2ServiceAccount#jwt-auth
I am using the second approach. Code snippet:
String privateKeyId = "my-private-key";
long now = System.currentTimeMillis();
String signedJwt = null;
try {
Algorithm algorithm = Algorithm.RSA256(null, privateKey);
signedJwt = JWT.create()
.withKeyId(privateKeyId)
.withIssuer("my-issuer")
.withSubject("my-subject")
.withAudience("https://www.googleapis.com/compute/v1/compute.machineTypes.list")
.withIssuedAt(new Date(now))
.withExpiresAt(new Date(now + 3600 * 1000L))
.sign(algorithm);
} catch (Exception e){
e.printStackTrace();
}
return signedJwt;
Then I perform get instances setting the returned token as Bearer authorization header but response is:
com.google.api.client.http.HttpResponseException: 401 Unauthorized
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
With same credentials I am able to access the SDK.
Thanks!
As per #DalmTo, you should be using the client library for Java. This is the link to get you started.

Receiving "Invalid 'changeType'" when subscribing to user created event

I am trying to create a Webhook (aka Subscription) for users who are created, updated, or deleted in Office 365.
With the "changeType": "updated" it works fine but with "changeType": "created" it returns an error:
This is the request:
{
"changeType": "created,updated,deleted",
"notificationUrl": "https://ourLink",
"resource": "users",
"expirationDateTime": "2017-12-16T14:49:57Z",
"clientState": "pe1g9gqiVsE6KnHTUuK9Tts3o660KOAw9YnavVfKhr22I7FlqC0tfMhpayxrqFP4orFPOjK0rppYtDicvxZosbvOEEgfy3YYoM3FGDwLQiW4MAdSCTdQkffuChjmB"
}
Error:
{
"header": 400,
"body": {
"error": {
"code": "InvalidRequest",
"message": "Invalid 'changeType' attribute: 'created'.",
"innerError": {
"request-id": "74454900-d3df-4962-b58e-cfd7ec7454bc",
"date": "2017-12-13T16:49:59"
}
}
}
}
Creating a subscription to a user resource is only available in the Beta API
but according to the documentation, it should work.
Based on the error message and that the User Webhook sample application only handles updated and deleted, this should be the expected behavior.
I'm also unable to find where in the documentation it states that a user resource accepts subscriptions for created. If you could provide a link I will make sure the documentation gets updated.

Resources