Google Analytics API in inserting goals using PHP - php

I need help regarding the returned error after initiating request:
Here's the request body:
{
"name": "Test Leads",
"id": "2",
"type": "Event",
"active": true,
"eventDetails": {
"eventConditions": [
{
"type": "Category",
"comparisonType": "EQUAL",
"expression": "Leads"
},
{
"type": "ACTION",
"comparisonType": "EQUAL",
"expression": "Create"
}
],
"useEventValue": true
}
}
Error:
{"error":{
"errors":[
{"domain":"global","reason":"backendError","message":"Backend Error"}
],
"code":500,
"message":"Backend Error"
}
}
Expected Goal Details when successfully posted:
https://www.screencast.com/t/5QOJ28Tnk
Can someone check the code and see what's wrong or missing?
Thanks.

"name": "Test Leads",
"kind": "analytics#goal",
"id": "2",
"type": "Event",
"active": true,
"eventDetails": {
"eventConditions": [
{
"type": "CATEGORY",
"matchType": "EXACT",
"expression": "Leads"
},
{
"type": "ACTION",
"matchType": "EXACT",
"expression": "Create"
}
],
"useEventValue": true
}
}```

Related

Elasticsearch batch not indexing all items using PHP client

I've been trying to build an index in ES and add the initial items to it (around 350k), using PHP.
I tried all kinds of batch sizes (from 10 items to 1k), check the count, check the threshold, but for some reason it doesn't index every item.
It just skips over some random items, without any errors in the batch result response. I feel like I tried everything and I have to idea what to do next
I'm using Amazon OpenSearch with the latest supported ES (7.10).
The index looks like this:
{
"wonder-search": {
"aliases": {},
"mappings": {
"properties": {
"address": {
"type": "text"
},
"city": {
"type": "text"
},
"city_id": {
"type": "integer"
},
"duration": {
"type": "integer"
},
"filename": {
"type": "text"
},
"geo_point": {
"type": "geo_point"
},
"icon": {
"type": "keyword"
},
"is_sandbox": {
"type": "integer"
},
"item_id": {
"type": "integer"
},
"item_label": {
"type": "keyword"
},
"latitude": {
"type": "float"
},
"longitude": {
"type": "float"
},
"search_text_caption_json": {
"type": "text",
"index_phrases": true
},
"search_text_city_json": {
"type": "text",
"index_phrases": true
},
"search_text_completion": {
"type": "completion",
"analyzer": "simple",
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50,
"contexts": [
{
"name": "type",
"type": "CATEGORY"
}
]
},
"search_text_country_json": {
"type": "text",
"index_phrases": true
},
"search_text_cuisine_name_json": {
"type": "text",
"index_phrases": true
},
"search_text_location_name_json": {
"type": "text",
"index_phrases": true
},
"search_text_state_json": {
"type": "text",
"index_phrases": true
},
"search_text_tag_name_json": {
"type": "text",
"index_phrases": true
},
"search_text_username_json": {
"type": "text",
"index_phrases": true
},
"sort": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"sort_score": {
"type": "double"
},
"type": {
"type": "text"
},
"user_icon": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"user_id": {
"type": "integer"
},
"username": {
"type": "keyword"
},
"vanity_url": {
"type": "keyword"
},
"video_count": {
"type": "integer"
}
}
},
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"mapping": {
"ignore_malformed": "true"
},
"number_of_shards": "1",
"provided_name": "wonder-search",
"creation_date": "1671003076106",
"number_of_replicas": "1",
"uuid": "YQh1q40WTneLE4MWDWhArw",
"version": {
"created": "7100199"
}
}
}
}
}
and one item looks like this:
{
"_index": "wonder-search",
"_type": "_doc",
"_id": "wq2LD4UBUAuy7FQPhtZh",
"_version": 1,
"_seq_no": 2003,
"_primary_term": 1,
"found": true,
"_source": {
"sort": "4004",
"item_id": "4934",
"user_id": "434",
"user_icon": "/site-content/avatars/Sp8AXjTJvMbRao2oZbuiUuSVH042-1597776099045.jpeg",
"username": "chuurros",
"item_label": "Kyoto Katsugyu【京都勝牛】",
"search_text_username_json": [
"chuurros"
],
"search_text_caption_json": [
"Absolutely love their gyukatsu (beef katsu) here! Delicious and will keep you wanting more! 🥰"
],
"search_text_city_json": [
"Toronto"
],
"search_text_state_json": [
"Ontario"
],
"search_text_country_json": [
"Canada"
],
"search_text_location_name_json": [
"Kyoto Katsugyu【京都勝牛】"
],
"search_text_tag_name_json": [
"japanese",
"restaurant",
"asian",
"dining",
"topcollection-4934"
],
"search_text_cuisine_name_json": [],
"type": "video",
"vanity_url": "",
"icon": "",
"city": "Toronto",
"city_id": "439",
"latitude": "43.65682410",
"longitude": "-79.37617410",
"address": "134 Dundas St E",
"duration": "9.57",
"video_count": "0",
"sort_score": "43",
"filename": "373d75fd-4292-4e5b-a239-4b1c39ffc86c.MOV",
"is_sandbox": "0",
"geo_point": {
"lat": "43.65682410",
"lon": "-79.37617410"
},
"search_text_completion": {
"input": [
"Kyoto Katsugyu【京都勝牛】"
],
"contexts": {
"type": [
"video"
]
}
}
}
}
Any ideas why does it work like this?

Wordpress 401 error: rest_forbidden. Sorry, you are not allowed to make proxied oEmbed requests

I'm getting 401 error on the following URL call on my Wordpress hosted on Windows IIS server:
https://example.com/wp-json/oembed/1.0/proxy?url=https://example.com/wp-content/uploads/img.jpg
{
"code": "rest_forbidden",
"message": "Sorry, you are not allowed to make proxied oEmbed requests.",
"data": {
"status": 401
}
}
The above URL is called by the Elementor gallery widget when I want to set an external image for it.
Although, the following URL is working on my Wordpress site:
https://example.com/wp-json/oembed/1.0?url=https://example.com/wp-content/uploads/img.jpg
{
"namespace": "oembed\/1.0",
"routes": {
"\/oembed\/1.0": {
"namespace": "oembed\/1.0",
"methods": ["GET"],
"endpoints": [{
"methods": ["GET"],
"args": {
"namespace": {
"default": "oembed\/1.0",
"required": false
},
"context": {
"default": "view",
"required": false
}
}
}
],
"_links": {
"self": [{
"href": "https:\/\/example.com\/wp-json\/oembed\/1.0"
}
]
}
},
"\/oembed\/1.0\/embed": {
"namespace": "oembed\/1.0",
"methods": ["GET"],
"endpoints": [{
"methods": ["GET"],
"args": {
"url": {
"description": "The URL of the resource for which to fetch oEmbed data.",
"type": "string",
"format": "uri",
"required": true
},
"format": {
"default": "json",
"required": false
},
"maxwidth": {
"default": 600,
"required": false
}
}
}
],
"_links": {
"self": [{
"href": "https:\/\/example.com\/wp-json\/oembed\/1.0\/embed"
}
]
}
},
"\/oembed\/1.0\/proxy": {
"namespace": "oembed\/1.0",
"methods": ["GET"],
"endpoints": [{
"methods": ["GET"],
"args": {
"url": {
"description": "The URL of the resource for which to fetch oEmbed data.",
"type": "string",
"format": "uri",
"required": true
},
"format": {
"description": "The oEmbed format to use.",
"type": "string",
"default": "json",
"enum": ["json", "xml"],
"required": false
},
"maxwidth": {
"description": "The maximum width of the embed frame in pixels.",
"type": "integer",
"default": 600,
"required": false
},
"maxheight": {
"description": "The maximum height of the embed frame in pixels.",
"type": "integer",
"required": false
},
"discover": {
"description": "Whether to perform an oEmbed discovery request for unsanctioned providers.",
"type": "boolean",
"default": true,
"required": false
}
}
}
],
"_links": {
"self": [{
"href": "https:\/\/example.com\/wp-json\/oembed\/1.0\/proxy"
}
]
}
}
},
"_links": {
"up": [{
"href": "https:\/\/example.com\/wp-json\/"
}
]
}
}
PHP: 7.4.16
Wordpress: 5.6.2
Windows Server: 2019

Swagger UI Access-Control-Allow-Origin Error

I have my Laravel PHP application where API is hosted on https://site.example.com and I have Swagger UP API Doc hosted on https://api.example.com. when I try API on Swagger API it gives Access-Control-Allow-Origin Error error. Following is my swagger.json
{
"openapi": "3.0.0",
"info": {
"title": "Seller-Hub",
"description": "",
"license": {
"name": "-"
},
"version": "1.1.0"
},
"servers": [
{
"url": "https://site.example.com/public/api/v1",
"description": "Dev server"
},
],
"paths": {
"/seller": {
"get": {
"tags": [
"Seller"
],
"summary": "Returns Seller Data",
"description": "Returns a map of Seller Data",
"operationId": "seller",
"parameters": [
],
"responses": {
"200": {
"description": "successful operation",
"headers":{
"Access-Control-Allow-Origin":{
"schema":{
"type": "string"
}
},
"Access-Control-Allow-Methods":{
"schema":{
"type": "string"
}
},
"Access-Control-Allow-Headers":{
"schema":{
"type": "string"
}
},
},
"content": {
"application/json": {
"schema": {
}
}
}
},
},
"security": [
{
"ApiSign": []
}
]
}
},
"components": {
"securitySchemes": {
"ApiSign": {
"type": "apiKey",
"in": "header",
"name": "authorization"
}
}
},
}
I am not getting where to pass Access control as headers. I have tried every possible way but no success. any help would be great. Thanks

How to read context parameters using php webhook in dialogflow

Need help with the following I writing a webhook in php, and need the ability to read the context parameters.
Can someone help me to understand how it can be done?
Here is my example JSON:
{
"id": "6e774dc2-2323-42b3-bd3c-ab64930f8b92",
"timestamp": "2017-12-22T21:12:19.094Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "Yes",
"action": "Triage.Triage-yes",
"actionIncomplete": false,
"parameters": {},
"contexts": [
{
"name": "triage-followup",
"parameters": {
"triagecriteria": [],
"roomEntity.original": "",
"roomname": "300",
"roomnames.original": "living",
"roomid": "200",
"context": "",
"roomnames": [
"living"
],
"counter": "400",
"roomEntity": "100",
"triagecriteria.original": ""
},
"lifespan": 3
}
],
"metadata": {
"intentId": "ecd4a2e5-65a0-41b2-ac72-edcf4d2e73f2",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"webhookResponseTime": 203,
"intentName": "Triage - yes"
},
"fulfillment": {
"speech": "Yes",
"source": "agent",
"displayText": "No",
"messages": [
{
"type": 0,
"speech": "Yes"
}
]
},
"score": 1
},
"status": {
"code": 200,
"errorType": "success",
"webhookTimedOut": false
},
"sessionId": "db8c1a4e-fa0c-4257-a536-78b63879eef9"
}
I want to be able to refer to [results][Contexts][Parameters]
I am using
$update_response = file_get_contents("php://input");
$update = json_decode($update_response, true, 512, JSON_BIGINT_AS_STRING);
and trying to access the value as $update["results"]["Contexts"]["Parameters"]["roomid"]
The names are case sensitive, and you need to be careful about trailing "s"es. Since some of the items are numerically indexed arrays, you'll need to include that as part of the index. Try
$update["result"]["contexts"][0]["parameters"]["roomid"]

How can i get json object results in php using php_decode and url

below is my json object result of google api now i want to get url of cover from it which is parameter 'thumbnail' in below json object,but i dont know how can i retrive it can anyone here help me out?
{
"kind": "books#volumes",
"totalItems": 1,
"items": [
{
"kind": "books#volume",
"id": "9VKCkifBlisC",
"etag": "hhhZjjV6arI",
"selfLink": "url",
"volumeInfo": {
"title": "Instructor's manual to accompany An introduction",
"authors": [
"Jean-Paul Tremblay",
"P. G. Sorenson"
],
"publishedDate": "1976",
"industryIdentifiers": [
{
"type": "ISBN_10",
"identifier": "0070651515"
},
{
"type": "ISBN_13",
"identifier": "9780070651517"
}
],
"pageCount": 278,
"printType": "BOOK",
"categories": [
"Computers"
],
"averageRating": 5.0,
"ratingsCount": 1,
"contentVersion": "0.0.1.0.preview.0",
"imageLinks": {
"smallThumbnail": "url",
/*this is what i need*/
"thumbnail": "url"
},
"language": "en",
"previewLink": "url",
"infoLink": "url",
"canonicalVolumeLink": "url"
},
"saleInfo": {
"country": "IN",
"saleability": "NOT_FOR_SALE",
"isEbook": false
},
"accessInfo": {
"country": "IN",
"viewability": "NO_PAGES",
"embeddable": false,
"publicDomain": false,
"textToSpeechPermission": "ALLOWED",
"epub": {
"isAvailable": false
},
"pdf": {
"isAvailable": false
},
"webReaderLink": "url",
"accessViewStatus": "NONE",
"quoteSharingAllowed": false
}
}
]
}
You could do like this..
$arr = json_decode($json,true);
echo $arr['items'][0]['volumeInfo']['imageLinks']['thumbnail'];
Demo

Categories