In spite of using Logger.log()method, nothing is displayed in the Log-box.
What should I do to show log messages in log-box?
After I sent message to chatbot using webhook(there is no problem. my chatbot return messages), I check log-box(above "Stackdriver Logging").but there is no message.
Add, use console.log instead of logger.log, i could watch logs on Stackdriverlogging. thanks.
var ACCESS_TOKEN = 'ACCESS_TOKEN_VALUE';
function doPost(e) {
var replyToken = JSON.parse(e.postData.contents).events[0].replyToken;
var userMessage = JSON.parse(e.postData.contents).events[0].message.text;
var url = 'https://api.line.me/v2/bot/message/reply';
UrlFetchApp.fetch(url, {
'headers': {
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer ' + ACCESS_TOKEN,
},
'method': 'post',
'payload': JSON.stringify({
'replyToken': replyToken,
'messages': [{
'type': 'text',
'text': userMessage + 'ンゴ',
}],
}),
});
Logger.log(userMessage.toString());
return ContentService.createTextOutput(JSON.stringify({'content': 'post ok'})).setMimeType(ContentService.MimeType.JSON);
}
Related
I've used Google Picker API to retrieve My Drive videos URLs and publish them in my app. So I want to change their sharing permission (as public) and disabled the download button with the copyRequiresWriterPermission option.
This is my code for change the permissions in the Picker callback function;
function pickerCallback(data, e) {
if (data.action == google.picker.Action.PICKED) {
var docs = data[google.picker.Response.DOCUMENTS];
var type = "anyone";
var role = "reader";
var urls = new Array();
for (var d = 0; d < docs.length; d++) {
var request1 = gapi.client.request({
'path': '/drive/v3/files/' + docs[d].id + '/permissions',
'method': 'POST',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + oauthToken
},
'body':{
'role': role,
'type': type
}
});
request1.execute(function(resp) {
console.log(resp);
});
urls.push(docs[d].url);
}
elements.push({name: 'url', value: urls});
// continue with an ajax funtion ...
}
};
That works fine, so I decided add a new request for change the donwload restriction:
var request2 = gapi.client.request({
'path': '/drive/v3/files/' + docs[d].id,
'method': 'POST',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + oauthToken
},
'body':{
'copyRequiresWriterPermission': true
}
});
request2.execute(function(resp) {
console.log(resp);
});
But only I obtained a 404 status. Also, I've tried with:
'/upload/drive/v3/files/' + docs[d].id
But the same problem.
I've tried the request with the File Id in the Drive API Demo and works. What is the error in the request2 code?
Scopes used:
var scope = [
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/drive.metadata",
"https://www.googleapis.com/auth/drive.readonly",
];
Updated code:
var request2 = gapi.client.request({
'path': '/drive/v3/files/' + docs[d].id ,
'method': 'PATCH',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + oauthToken
},
'body':{copyRequiresWriterPermission: true}
});
request2.execute(function(resp) {
console.log(resp);
});
This code execute without problems, but nothing happens because I need to uncheck this parameter:
Is it possible?
If you want to update a File in drive, the request method should be PATCH not POST.
Example:
var request2 = gapi.client.request({
'path': '/drive/v3/files/' + docs[d].id,
'method': 'PATCH',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + oauthToken
},
'body': {
copyRequiresWriterPermission: true
}
});
request2.execute(function(resp) {
console.log(resp);
});
References:
Drive API Files: update
Can some one give me example of how to convert ajax to axios ?
I am trying to convert this code into axios
$.ajax({
type: 'POST',
url: 'http://example.com/storeauthcode',
// Always include an `X-Requested-With` header in every AJAX request,
// to protect against CSRF attacks.
headers: {
'X-Requested-With': 'XMLHttpRequest'
},
contentType: 'application/octet-stream; charset=utf-8',
success: function(result) {
// Handle or verify the server response.
},
processData: false,
data: authResult['code']
});
axios.post('http://example.com/storeauthcode', authResult['code'], {
headers: {
'X-Requested-With': 'XMLHttpRequest'
'Content-Type: 'application/octet-stream; charset=utf-8',
},
transformResponse: (data) => { // do something with your data },
});
However a better place for the content-type would be the axios instance config itself.
Configure once globally:
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
Then per request:
const result = await axios.post(
'http://example.com/storeauthcode',
authResult['code'],
{
headers: {
'Content-type': 'application/octet-stream; charset=utf-8'
}
}
);
I need to change Heroku config vars programatically from an apps script.
I have the Heroku Platform API Reference, including info on OAuth, but I'm not experienced enough to use these to write the Google Apps Script code from scratch and a sample implementation would be very helpful.
Thanks.
Luckily it wasn't as complicated as it originally appeared -- in a good part, because OAuth wasn't necessary, just an API KEY from Heroku on their Manage Account page.
HEROKU_ADDRESS = 'https://api.heroku.com/apps';
function getApps() {
// Get all apps of Bearer, including their IDs and names. Either ID or name can be used later on as APP_ID.
var options = {
'method' : 'get',
'headers' : {
'Accept': 'application/vnd.heroku+json; version=3',
'Authorization': 'Bearer '+ HEROKU_API_KEY
},
};
var response = UrlFetchApp.fetch(HEROKU_ADDRESS, options);
Logger.log(response.getContentText());
}
function getConfigVars() {
// Get all config-vars of App
var options = {
'method' : 'get',
'headers' : {
'Accept': 'application/vnd.heroku+json; version=3',
'Authorization': 'Bearer '+ HEROKU_API_KEY
},
};
var response = UrlFetchApp.fetch(HEROKU_ADDRESS+'/' + APP_ID +'/config-vars', options);
Logger.log(response.getContentText());
}
function updateConfigVars(newConfigVars) {
// Set/Update some config-vars of App
// returns all config-vars
var options = {
'method' : 'patch',
'headers' : {
'Accept': 'application/vnd.heroku+json; version=3',
'Authorization': 'Bearer '+ HEROKU_API_KEY,
'Content-Type': 'application/json'
},
'payload': JSON.stringify(newConfigVars)
};
var response = UrlFetchApp.fetch(HEROKU_ADDRESS+'/' + APP_ID +'/config-vars', options);
Logger.log(response.getContentText());
}
function delConfigVar(ConfigVarName) {
// Delete a config-var of App (set to null)
// returns all remaining config-vars
var ConfigVar2del = {};
ConfigVar2del[ConfigVarName] = null;
var options = {
'method' : 'patch',
'headers' : {
'Accept': 'application/vnd.heroku+json; version=3',
'Authorization': 'Bearer '+ HEROKU_API_KEY,
'Content-Type': 'application/json'
},
'payload': JSON.stringify(ConfigVar2del)
};
var response = UrlFetchApp.fetch(HEROKU_ADDRESS+'/' + APP_ID +'/config-vars', options);
Logger.log(response.getContentText());
}
function del() {
delConfigVar('name');
}
function update() {
var newConfigVars = {
'name': 'some value',
'test': 770
};
updateConfigVars(newConfigVars);
}
With these functions one can get info on all of Bearer's Heroku apps, including their names and IDs that can be subsequently used to get all config vars of the app, or modify/delete some of those config vars.
I am trying to pass data to yii controller through ajax.
This is my ajax code in extJs:
Ext.Ajax.request({
url:action_url,
type: 'POST',
dataType: 'json',
data:{insurance: insurance_id},
success:function(res){
console.log(res);
},
In Yii Controller :
public function actionTest()
{
$response = Yii::$app->response;
$response->format = \yii\web\Response::FORMAT_JSON;
if(Yii::$app->request->isAjax)
{
$data = Yii::$app->request->post();
$response->data = ['data' => $data];
} else {
$response->data = ['fail' => 'failed'];
}
return $response;
Yii::$app->end();
}
I am getting the response as :
{request: {…}, requestId: 6, status: 200, statusText: "OK",…}
responseText:"{"data":[]}"
I am stuck with this. please help.
Added _csrf with other parameters.
Ext.Ajax.request({
url:action_url,
method: 'POST',
dataType: 'json',
params:{insurance: insurance_id, _csrf : csrf_tok}
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
success:function(res){
console.log(res);
},
I am trying to develop an application using reactjs as front end framework and laravel 5.6 as back end framework. I am trying to send AJAX request like below
import Auth from '../services/Auth';
var address_data = {
name :'foysal',
address :'foysal',
telephone_no:'foysal',
email :'foysal',
}
fetch('http://127.0.0.1:8000/api/addresses/store/',address_data, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + Auth.getToken(),
},
body: JSON.stringify()
})
.then((response) => response.json())
.then((responseData) => {
console.log(responseData);
})
I am getting below errors
Try changing your fetch request to initiate POST action verb like this
fetch('http://127.0.0.1:8000/api/addresses/store/', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + Auth.getToken(),
},
body: JSON.stringify(address_data)
}).then(res => res.json())
.catch(error => console.error('Error:', error))
.then(response => console.log('Success:', response));