I am working on creating labels using JavaScript Gmail API.
function createLabel(userId, newLabelName, callback) {
var request = gapi.client.gmail.users.labels.create({
'userId': userId,
'label': {'name': newLabelName}
});
request.execute(callback);}
This is the code of Developer API Example
I am able to authenticate and even I'll get the label list but while creating the label I am getting the below error.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "Invalid request"
}
],
"code": 400,
"message": "Invalid request"
}
}
But when I am using the Try It example It's working but only difference is it's do the POST request with key={Your auth key} which the example provided won't attach that part to URL.
The data you send should be in the resource-parameter, and labelListVisibility and messageListVisibility are also mandatory fields:
function createLabel(userId, newLabelName, callback) {
gapi.client.gmail.users.labels.create({
userId: userId,
resource: {
name: newLabelName,
labelListVisibility: 'labelShow',
messageListVisibility: 'show'
}
}).execute(callback);
}
Related
I wrote an api in user.controller using dto of 'class-validator'.
#Post('/')
public async createUser(
#Res() res,
#Body() createUserDto: CreateUserDto,
) {
... do something
}
And I put useGlobalPipes in main.ts.
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
transform: true,
forbidNonWhitelisted: true,
transformOptions: {
enableImplicitConversion: true,
},
}),
);
When I request to the api, I get a response below.
{
"statusCode": 400,
"message": [
"userName should not be empty",
"userName must be a string",
],
"error": "Bad Request"
}
So far, it works without problem with nestjs.
But I want to get a custom response like this.
{
"code": 400,
"errorReason": [
"userName should not be empty",
"userName must be a string",
],
"msg": "Bad Request",
"success": false
}
Can I get this custom response maintaining the code above?
If it can do it, could you give me some advice or some code for this?
Thank you for reading my question.
In Nest, pipes are good for validation, transforming an incoming object, maybe talking to a database in some circumstances, and throwing errors if anything goes wrong. If you want to change the response, after an error is thrown, you'll need to look into using an ExceptionFilter Where you can do something like
#Catch()
export class CatchAllFilter implements ExceptionFilter {
catch(exception: Error, host: ArgumentHost) {
res
.status((exception.getStatus && exception.getStatus()) || 500)
.send({
(exception.getResponse && ...exception.getResponse()) || ...{ message: exception.message },
success: false
});
}
}
You're bound to get type errors with the above code, but it should lead you on the right track
I'm using the guide from https://docs.amazonaws.cn/en_us/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.02.html to learn how to load data from a json into a dynamoDB table. I have done step 2, however, when I run my code, only some movie files are successfully put into the table and some are not. For a movie that cannot be added, I receive this error:
Unable to add movie Meet Dave . Error JSON: {
"message": "Requested resource not found",
"code": "ResourceNotFoundException",
"time": "2020-11-30T17:38:59.402Z",
"requestId": "2D23NEFAB33E62C6PEFUFGGNM7VV4KQNSO5AEMVJF66Q9ASUAAJG",
"statusCode": 400,
"retryable": false,
"retryDelay": 28.791430704572328
}
Every time I delete the db and try re-run my code, different movies are successfully added and unsuccessfully added. My code is identical to the step 2 of the guide on the link above.
var allMovies = JSON.parse(fs.readFileSync("movie_data.json", "utf8"));
allMovies.forEach(function (movie) {
var movie_params = {
TableName: "Movies",
Item: {
year: movie.year,
title: movie.title,
info: movie.info,
},
};
docClient.put(movie_params, function (err, data) {
if (err) {
console.error(
"Unable to add movie",
movie.title,
". Error JSON:",
JSON.stringify(err, null, 2)
);
} else {
console.log("PutItem succeeded:", movie.title);
}
});
});
The movie data is a json file containing a list movies with attributes: title, year and info. Does anyone have any idea why this is not working correctly i.e. not putting all of the data successfully into the db table?.
I'm trying to run a simple query against my Google Cloud datastore using google-api-nodejs-client. I want to query for all entities matching a given kind. When I run this query using the "Try it now" tool it works fine:
Request
POST https://www.googleapis.com/datastore/v1beta2/datasets/healthier-staging/runQuery?key={YOUR_API_KEY}
{
"query": {
"kinds": [
{
"name": "Subscriber"
}
]
}
}
Response
200 OK
{
"batch": {
"entityResultType": "FULL",
"entityResults": [
{
"entity": {
"key": {
"partitionId": {
"datasetId": "s~healthier-staging"
},
"path": [
{
"kind": "Subscriber",
"name": "+1215XXXXXXX"
}
]
},
"properties": {
...
I'm able to authenticate using my credentials, create a transaction, etc. so I know it's not an authentication issue.
Here's the code I'm trying to run in Node:
this.datastore.runQuery({
datasetId: 'healthier-staging',
query: {
kinds: [{name: 'Subscriber'}]
},
}, (function(err, result) {
if (err) {
console.error(err);
return;
}
}).bind(this));
When I try to run the same query using the Node module, I get this error:
{ [Error: one of fields Query.query and Query.gql_query must be set]
code: 400,
errors:
[ { domain: 'global',
reason: 'INVALID_ARGUMENT',
message: 'one of fields Query.query and Query.gql_query must be set' } ] }
This doesn't make sense, since I've specified the query field. I've tried all sorts of things: removing datasetId (produces an error about needing datasetId), using gql_query instead (same error), encapsulating the datasetId inside a transaction and passing that along inside readOptions, etc.
Is this a bug or am I doing something silly?
Thanks!
I mentioned this on your other StackOverflow question, but your request should be included in the resource section:
this.datastore.runQuery({
datasetId: 'healthier-staging',
resource: {
query: {
kinds: [{name: 'Subscriber'}]
},
},
}, (function(err, result) {
if (err) {
console.error(err);
return;
}
}).bind(this));
I am trying to delete a playlist that I have created but keep receiving a 404 error.
I have a global var playlistId to remember the playlistId that I have created.
var playlistId
I create the playlist like so :
function createPlaylist() {
var request = gapi.client.youtube.playlists.insert({
part: 'snippet,status',
resource: {
snippet: {
title: 'hard coded title',
description: 'Hard Coded Description'
},
status: {
privacyStatus: 'private'
}
}
});
request.execute(function(response) {
var result = response.result;
if (result) {
playlistId = result.id;
console.log("created playlist " + playlistId)
}
});
}
Then I delete a playlist like so :
function deletePlaylist() {
var request = gapi.client.youtube.playlistItems.delete({
id: playlistId
}).execute();
}
404 Error that I receive is :
{
"error": {
"errors": [
{
"domain": "youtube.playlistItem",
"reason": "playlistItemNotFound",
"message": "Playlist item not found.",
"locationType": "parameter",
"location": "id"
}
],
"code": 404,
"message": "Playlist item not found."
}
}
I am giving the playlistId of the PlayList that I have created yet the playlist can not be deleted.
Can anyone give some guidance?
deletePlaylist appears to be attempting to delete a PlaylistItem (i.e. a video) rather than a Playlist itself. Could you try replacing playlistItems with playlists?
I am getting this error while we are uploading image to facebook.And i am given the permissions.
https://graph.facebook.com/me/photos
{
"error": {
"message": "An active access token must be used to query information about the current user.",
"type": "OAuthException",
"code": 2500
}
}
This is my as3
var params:Object = {image:img, message:'vcxv', fileName:'vcxvc',name: 'My Card'};
Facebook.api('/me/photos', onSaveToPhotoAlbumComplete, params, "POST");
Please help me.
You have to add an Access Token to Object:
access_token:Facebook.getAuthResponse().accessToken
var params:Object = {image:img, message:'vcxv', fileName:'vcxvc',name: 'My Card', access_token:Facebook.getAuthResponse().accessToken};
Facebook.api('/me/photos', onSaveToPhotoAlbumComplete, params, "POST");