Show specific attachment using json api for Wordpress - json

When I go to:
example.com/api/get_tag_posts/?dev=2&slug=ME3022&include=attachments
I see:
{
status: "ok",
count: 1,
pages: 1,
tag: {
id: 17,
slug: "me3022",
title: "ME3022",
description: "",
post_count: 1
},
posts: [
{
id: 181,
attachments: [
{
id: 397,
url: "http://example.com/files/2012/10/WebInstruction_TCH.pdf",
slug: "webinstruction_tch-3",
title: "Traditional Chinese",
description: "",
caption: "Traditional Chinese",
parent: 181,
mime_type: "application/pdf"
},
{
id: 398,
url: "http://example.com/files/2012/10/WebInstruction_SCH.pdf",
slug: "webinstruction_sch-3",
title: "Simplified Chinese",
description: "",
caption: "Simplified Chinese",
parent: 181,
mime_type: "application/pdf"
},
What I want to show is a specific attachment instead of all of the attachments. How can I do that?

To get the a specific attachment &include=attachments,id=51

Related

How to remove specific lines with a pattern inside a json file?

I have a very large json file with an error that I need to fix.
{
id: 1,
name: 'Human',
type: {
id: { <==== here
id: 2,
name: 'Body',
image: 'body.png',
}, <==== here
},
},
I need to remove this id: { and the closing brace } lines inside type. How to remove them to make the object look like this?
{
id: 1,
name: 'Human',
type: {
id: 1,
name: 'Body',
image: 'body.png',
},
},

Google script; setValues from API

I have problems set the values of an API into google sheets. The data set which is provided looks like this:
const data = [
{
quantity: 10000,
unitprice: 30.37,
id: 168586
},
{
quantity: 2000,
unitprice: 27.85,
id: 168583
},
{
quantity: 20,
unitprice: 150000,
id: 135693
},
{
quantity: 2109,
unitprice: 25.01,
id: 168586
},
{
quantity: 8434,
unitprice: 34.72,
id: 168589
},
{
quantity: 1,
unitprice: 5,
id: 168583
},
{
quantity: 560,
unitprice: 180.23,
id: 158191
}
];
If I use the setValue function in google sheets it only paste the first block but ignores the other ones. If I use setValues I get the error:
"Exception: The parameters (number[]) don't match the method signature for SpreadsheetApp.Range.setValues."
Someone has an idea what I can do?
Your data is not a 2D array, you have to detail each object with their properties
Try
function decode() {
const data = [
{
quantity: 10000,
unitprice: 30.37,
id: 168586
},
{
quantity: 2000,
unitprice: 27.85,
id: 168583
},
{
quantity: 20,
unitprice: 150000,
id: 135693
},
{
quantity: 2109,
unitprice: 25.01,
id: 168586
},
{
quantity: 8434,
unitprice: 34.72,
id: 168589
},
{
quantity: 1,
unitprice: 5,
id: 168583
},
{
quantity: 560,
unitprice: 180.23,
id: 158191
}
];
let values = []
values.push(['quantity', 'unitprice', 'id'])
data.forEach(d => {
values.push([d.quantity, d.unitprice, d.id])
})
SpreadsheetApp.getActiveSheet().getRange(1, 1, values.length, values[0].length).setValues(values)
}

jsondecode loading issue in dart

I try to run below code in flutter App but it loads half JSON data, same API when running for a web app it works fine.
Any idea how to solve this issue?
Example
Future <List> test() async{
final response = await http.post(
"https://xyz/allData",
body: jsonEncode({
"email": "email"
}),
headers: {
HttpHeaders.contentTypeHeader: ContentType.json.toString(),
HttpHeaders.authorizationHeader: token
});
final data= json.decode(response.body);
OR
Map<String, dynamic> data =json.decode(response.body);
Error
half JSON fetch by above code
below content I recieved :
{success: true, msg: Loaded, content:
{total: 3, on: 0, off: 3,
on: {},
off: {
11: {id: 11, last_data: N/A,value: {N/A: {name: N/A, value: N/A}},
name: 01, type: temp, upper: 20, lower: 10, email: [], phn_list: [], id: 01,status: 0, freq: 10, description: 01, status_notf: 0, lat_map: 0, lng_map: 0, html: html},
12: {id: 12, last_data: N/A, value: {N/A: {name: N/A, value: N/A}},
name: 02, type: temp, upper: 20, lower: 10, email: [], phn_list: [], id: 02, status: 0,freq: 10, description: 02, status_notf: 0, lat_map: 0, lng_map

How to create dynamic content/Pages using JSON files in Gatsby?

I wish to create a complex routing in Gatsby using multiple JSON files:
First JSON file is based on routing:
File Location: /src/data/route.json
[
{
type: "Article",
title: "Post One",
slug: "/post-one",
data: "post-one.json"
},
{
type: "Course",
title: "Course One",
slug: "/course-one",
data: "course-one.json"
},
...
]
It is the Json file which contains route data.
Now in post-one.json file contains all the required data about the post that is required to render the post.
File Location: /src/data/articles/post-one.json
Routes: /post-one
{
title: "Post One",
head: {
title: "Some title here",
image: "/path/to/image.jpg",
description: "Some description here..."
},
body: {
// Body data here
...
}
}
But the main problem arises now as the courses is the collection of the different chapters.
Now for the main course page:
File location : /src/data/courses/course-name.json
Route is like: /course-name
{
title: "Course One",
head: {
title: "Some title here",
image: "/path/to/image.jpg",
description: "Some description here..."
},
info: {
// Some info about the course...
},
chapter: [
{
title: "chapter one",
slug: "/:courseId/chapter-one",
description: "Something about the chapter"
},
{
title: "chapter two",
slug: "/:courseId/chapter-two",
description: "Something about the chapter"
},
...
//Multiple chapters in the same course
]
}
Now the chapters will have the data like
File location : /src/data/chapters/chapter-name.json
Route: /courseId/chapter-name
{
title: "Chapter one",
description: "Some description here",
body: {
...
//Content for the body that can be rendered easily
}
}

Is it possible to get the number of likes on a Facebook status without an access token?

I got this on the status:
{
id: "100006579168423_1524160864479871",
from: {
id: "100006579168423",
name: "Terry Xu",
broadcast_name: "Terry X."
},
message: "test again #terryxu",
privacy: {
value: ""
},
place: {
id: "X",
name: "X",
location: {
city: "X",
country: "X",
latitude: X,
longitude: X,
street: "X",
zip: "X"
}
},
type: "status",
created_time: "2014-08-01T01:33:31+0000",
updated_time: "2014-08-01T01:33:31+0000",
network: "facebook",
facebook_id: "100006579168423_1524160864479871",
kind: "status",
order_id: "100006579168423_1524160864479871",
entity_id: "100006579168423_1524160864479871",
score: "100006579168423_1524160864479871",
queued_at: 1406857103686,
timeline_id: "86a7a49e-191c-11e4-91cf-0a3ce06e3fe5"
}
But shares and likes are not among them. Is it possible to get the number of likes on a Facebook status without an access token?