Caught exception: {
"error": {
"code": 401,
"message": "ScriptError",
"errors": [
{
"message": "ScriptError",
"domain": "global",
"reason": "unauthorized"
}
],
"status": "UNAUTHENTICATED"
}
}
gs code:
function createForms() {
var form = FormApp.create('New Form');
Logger.log('Published URL: ');
}
If I remove var form = FormApp.create('New Form'), then it works
Related
what is the correct way to get the conversation/messages on a Facebook page?
I am using:
https://graph.facebook.com/v13.0/{page-id}/conversations which returns
{
"data": [
{
"id": "t_XXXX",
"updated_time": "2022-05-25T12:37:30+0000"
}
}
Now trying to get the messages with https://graph.facebook.com/v13.0/{page-id}/conversations/t_XXXX/messages throws
{
"error": {
"message": "Unknown path components: /messages",
"type": "OAuthException",
"code": 2500,
"fbtrace_id": "asdf"
}
}
I've tried building and sending the REST request using the Google Tables: insert page with the following (sanitised) values:
Request parameters
projectId:prj-name
datasetId:dataset_name
Request body
{
"view": {
"useLegacySql": false,
"query": "SELECT * FROM `prj-name.dataset_name.hello_world`"
},
"type": "VIEW",
"tableReference": {
"projectId": "prj-name",
"datasetId": "dataset_name",
"tableId": "v_hello_world"
}
}
This post suggests these parameters should work, but Google returns the following response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Output field used as input"
}
],
"code": 400,
"message": "Output field used as input"
}
}
I've experimented with the REST properties and I think the 400 issue is caused by the inclusion of the tableReference property. But if I exclude it I get the following alternative error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Required parameter is missing"
}
],
"code": 400,
"message": "Required parameter is missing"
}
}
It's a shame that the "Required parameter" is not named in this error message!
I can use this code method to create the view but that code method throws an exception when patching views.
Help is appreciated. I'd rather not have to maintain two different ways of managing views in my code.
Thanks.
Remove "type": "VIEW", from your request.
That's not an input parameter. It's an output field from the response.
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#resource
I'm unable to get CPM data from my Youtube reports:
I'm getting:
{
"error": {
"code": 403,
"message": "Forbidden",
"errors": [
{
"message": "Forbidden",
"domain": "global",
"reason": "forbidden"
}
]
}
}
I don't even know where to begin to debug this, and I haven't found anything online.
I'm just trying to curl the endpoint, mirroring this: HERE
Notice that once you finish the oauth process, User will see
"You do not have permission to execute this method." and the 403
Also, Notice if you remove 'CPM' from the list of metrics, this will work.
Example:
curl --header "Authorization: Bearer _____access_token____" -e "https://developers.google.com" https://content-youtubeanalytics.googleapis.com/v2/reports\?endDate\=2014-06-30\&ids\=channel%3D%3DMINE\&metrics\=cpm\&startDate\=2014-05-01\&key\=_____api_key____
I'm getting the refresh token via:
<script>
var auth2;
var SCOPE = ['https://www.googleapis.com/auth/adwords',
'https://www.googleapis.com/auth/yt-analytics.readonly',
'https://www.googleapis.com/auth/youtube',
'https://www.googleapis.com/auth/yt-analytics-monetary.readonly',
'https://www.googleapis.com/auth/youtubepartner-channel-audit',
'https://www.googleapis.com/auth/youtubepartner',
'https://www.googleapis.com/auth/youtube.readonly',
] ;
function initClient() {
auth2 = gapi.auth2.init({
'clientId': 'my-client-id',
'scope': SCOPE.join(' '),
'prompt': 'consent',
})
}
function handleClientLoad() {
gapi.load('auth2', initClient);
}
</script>
<script async defer src="https://apis.google.com/js/api.js"
onload="this.onload=function(){};handleClientLoad()"
onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>
the access token I'm using is from the refresh token via:
https://www.googleapis.com/oauth2/v4/token?client_id={my_client_id}&client_secret={my_client_secret}&refresh_token={my_refresh_token}&grant_type=refresh_token
and I'm getting:
{
"access_token": "ya29.GlvyBZVPpC.....",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/adwords https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/youtube.readonly https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/yt-analytics.readonly https://www.googleapis.com/auth/yt-analytics-monetary.readonly",
"id_token": "eyJhbGciOiJSUz...."
}
I don't believe it's an issue with my scopes as I am not getting a 403 like:
{
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"errors": [
{
"message": "Request had insufficient authentication scopes.",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
For first I use this solution - http://www.yiiframework.com/doc-2.0/guide-rest-error-handling.html
But, I want to customize two types error.
When model validation wrong.
When something wrong (Exceptiin)
If model validation wrong i get response, like that:
{
"success": false,
"data": [
{
"field": "country_id",
"message": "Country Id cannot be blank."
},
{
"field": "currency_id",
"message": "Currency Id cannot be blank."
},
{
"field": "originator_id",
"message": "Originator Id cannot be blank."
}
]
}
But i want like that:
{
"success": false,
"data": [
"errors": [
{
"field": "country_id",
"message": "Country Id cannot be blank."
},
{
"field": "currency_id",
"message": "Currency Id cannot be blank."
},
{
"field": "originator_id",
"message": "Originator Id cannot be blank."
}
]
]
}
Second type error i get
{
"success": false,
"data": {
"name": "Exception",
"message": "Invalid request arguments",
"code": 0,
"type": "yii\\base\\InvalidParamException",
]
}
}
But i Want:
{
"success": false,
"data": {
"errors" : 1, <----------------
"name": "Exception",
"message": "Invalid request arguments",
"code": 0,
"type": "yii\\base\\InvalidParamException",
]
}
}
Because in anyway user get 200 Response and they don know about error or mistake.
If you are using default yii/rest/Controller model with error send 422.
Use yii/rest/Controller or yii/rest/ActiveController or extend it.
Or use own Serializer
http://www.yiiframework.com/doc-2.0/yii-rest-serializer.html
Maybe this could guide you, how to change error format:
class JsonErrors
{
public static function validation($model)
{
Yii::$app->response->statusCode = 422;
//Yii::$app->response->format = 'json';
$errorArray = [];
foreach($model->getErrors() as $key => $val) {
$errorArray[] = [
'field' => $key,
'message' => implode(', ', $val) // $val is array (can contain multiple error messages)
];
}
return $errorArray;
}
}
// in controller:
return JsonErrors::validation($model);
// config:
'on beforeSend' => function ($event) {
$response = $event->sender;
if($response->statusCode == 422)
{
$details = $response->data;
if(isset($response->data["message"]) && is_string($response->data["message"])) $details = $response->data["message"];
if(isset($response->data["message"]) && is_array($response->data["message"])) $details = json_decode($response->data['message']);
$response->data = [
'message' => 'Please correct your data with correct values.',
'details' => $details
];
}
}
I am trying to create agreement using paypal rest api.
POST https://api.sandbox.paypal.com/v1/payments/billing-agreements
In the request body i am passing "agreement_details" and other required fields such as name , description etc as per the documentation.
https://developer.paypal.com/docs/api/payments.billing-agreements#agreement_create
"agreement_details": {
"outstanding_balance": {
"value": "0.00"
},
"cycles_remaining": "4",
"cycles_completed": "0",
"final_payment_date": "2016-12-22T20:53:43Z",
"failed_payment_count": "0"
}
Status: 400 Bad Request
{
"name": "VALIDATION_ERROR",
"details": [
{
"field": "agreement_details",
"issue": "Field is invalid in a request."
}
],
"message": "Invalid request. See details.",
"information_link": "https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR",
"debug_id": "2fcb57fb9581f"
}