For the last few hours, I have been trying to find a solution to updating/uploading videos to many different languages throw the YouTube V3 API.
I can set the defaultLanguage,
"defaultLanguage": string
I can set video title and description,
"title": string,
"description": string,
or maybe there is a way of uploading many different snippets in different languages?
"snippet": {
"publishedAt": datetime,
"channelId": string,
"title": string,
"description": string,
"thumbnails": {
(key): {
"url": string,
"width": unsigned integer,
"height": unsigned integer
}
},
I don't see a way of translating the title and descriptions.
I see that it might be possible to do with the "localized" property but, I do not know if it is even possible or if it is the best way to do it.
"localized": {
"title": string,
"description": string
},
I would like to have some suggestions since I'm so new to YouTube API and I find this would be a very easy question to answer if you knew the answer, I do not expect any code or a complex solution but just to be guided, thanks for the help.
I found the solution, localizations is what it's called.
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.videos.update
PUT https://www.googleapis.com/youtube/v3/videos?part=localizations&key={YOUR_API_KEY}
{
"id": "kE7dYgd3F8E", //https://www.youtube.com/edit?video_id=kE7dYgd3F8E
"localizations": {
"es-do": { //local codes, http://www.science.co.il/Language/Locale-codes.php
"title": "Translated title",
"description": "Translated description"
}
}
}
Related
So let's say I have a resources called articles. These have a numeric id and you can access them under something such as:
GET /articles/1 for a specific article.
And let's say that returns something like:
{
"data": {
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON:API paints my bikeshed!",
"body": "A bunch of text here"
}
}
}
Now my question is how to handle a request to GET /articles. I.e. how to deal with the request to the collection.
You see, accessing the body of the article is slow and painful. The last thing I want this REST API to do is actually try to get all that information. Yet as far as I can tell the JSON API schema seems to assume that you can always return full resources.
Is there any "allowed" way to return just the IDs (or partial attributes, like "title") under JSON API while actively not providing the ability to get the full resource?
Something like:
GET /articles returning:
{
"data": [
{
"type": "article_snubs",
"id": 1,
"attributes": {
"title": "JSON:API paints my bikeshed!"
}
}, {
"type": "article_snubs",
"id": 2,
"attributes": {
"title": "Some second thing here"
}
}
]
}
Maybe with links to the full articles?
Basically, is this at all possible while following JSON API or a REST standard? Because there is absolutely no way that GET /articles is ever going to be returning full resources due to the associate cost of getting the data, which I do not think is a rare situation to be in.
As far as I understand the JSON API specification there is no requirement that an API must return all fields (attributes and relationships) of a resource by default. The only MUST statement regarding fields inclusion that I'm aware of is related to Sparse Fieldsets (fields query param):
Sparse Fieldsets
[...]
If a client requests a restricted set of fields for a given resource type, an endpoint MUST NOT include additional fields in resource objects of that type in its response.
https://jsonapi.org/format/#fetching-sparse-fieldsets
Even so this is not forbidden by spec I would not recommend that approach. Returning only a subset of fields makes consuming your API much harder as you have to consult the documentation in order to get a list of all supported fields. It's much more within the meaning of the spec to let the client decide which information (and related resources) should be included.
The "attributes" object of a JSON-API doc does not need to be a complete representation:
attributes: an attributes object representing some of the resource’s data.
You can provide a "self" link to get the full representation, or perhaps even a "body" link to get just the body:
links: a links object containing links related to the resource.
E.g.
{
"data": [
{
"type": "articles_snubs",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!"
},
"links": {
"self": "/articles/1",
"body": "/articles/1/body"
}
},
{
"type": "article_snubs",
"id": "2",
"attributes": {
"title": "Some second thing here"
},
"links": {
"self": "/articles/2",
"body": "/articles/2/body"
}
}
]
}
Am reading this "issue" from the guys from adaptive cards, and am trying to use their parsing way in my own project with no results. Here´s the entire thing https://github.com/microsoft/AdaptiveCards/issues/2448 the parsing section is below. Does this implementation really work?
JSON.parse Example
This is an Azure DevOps response where the message property is a JSON-serialized string. In order to access values within the string, we need to use the JSON.parse function in our template.
Data
{
"id": "1291525457129548",
"status": 4,
"author": "Matt Hidinger",
"message": "{\"type\":\"Deployment\",\"buildId\":\"9542982\",\"releaseId\":\"129\",\"buildNumber\":\"20180504.3\",\"releaseName\":\"Release-104\",\"repoProvider\":\"GitHub\"}",
"start_time": "2018-05-04T18:05:33.3087147Z",
"end_time": "2018-05-04T18:05:33.3087147Z"
}
Usage
{
"type": "TextBlock",
"text": "{JSON.parse(message).releaseName}"
}
Resulting In
{
"type": "TextBlock",
"text": "Release-104"
}
I've started using Moshi along with Retrofit 2 and have run into an issue parsing an array of objects within the parent object that is returned from the service call. The returned JSON looks like this:
{
"acf": {
"email": "dirk#dirkgently.com",
"address": "24 Cortland Avenue",
"country": "US",
"description": "Oh my goodness",
"created_at": "1416672067",
"updated_at": "1416672067",
"facebook": "",
"contact": "Dirk Gently",
"photos": [
{
"file": 3525
},
{
"file": 3526
},
{
"file": 6110
},
{
"file": 3527
},
{
"file": 3528
},
{
"file": 6700
},
{
"file": 7404
},
{
"file": 7419
}
],
"latitude": "40.801249",
"longitude": "-99.746280"
}
}
I'm getting the following exception with the 'photos' field:
com.squareup.moshi.JsonDataException: Expected BEGIN_ARRAY but was
STRING at path $[0].acf.photos
I've defined the models like so:
public class Acf {
private String email;
private String address;
List<Photo>photos;
}
public class Photo {
public int file;
}
I've tried declaring the property in the model in various other ways, and read through the docs to try to figure out what I'm doing wrong. I'm stuck at this point and could really use a second set of eyes to point me in the right direction. I have a feeling I'm missing something painfully simple and obvious. Thanks in advance to anyone that can help. If I've left out any pertinent info let me know and I'll update the post.
Update: I've found that this exception only occurs when I fetch multiple ACFs. If I do a request for a single object everything parses correctly.
Based on the error it sounds like the endpoint you're calling is possibly returning different types for that parameter (i.e. a string when you're expecting an array). Try changing it from a List<> to an Object and see if the call succeeds. You should be able to type-check the Object and cast whatever you need from it. An alternative would be to use a custom type adapter, but I'm not sure how to accomplish that using Moshi. Good luck.
I'm building a front end using WP JSON, and I need (among other things) the name of the author of each post.
In V1, this was easy - here's a fragment of a typical post object from calling http://example.com/wp-json/posts/1:
{
"ID": 1,
"title": "Hello world!",
"status": "publish",
"type": "post",
"author": {
"ID": 1,
"name": "admin",
"slug": "admin",
"URL": "",
"avatar": "http:\/\/0.gravatar.com\/avatar\/c57c8945079831fa3c19caef02e44614&d=404&r=G",
"meta": {
"links": {
"self": "http:\/\/example.com\/wp-json\/users\/1",
"archives": "http:\/\/example.com\/wp-json\/users\/1\/posts"
}
}
},
But in V2, for author, all we get back is the ID (an integer). Passing this back to the API, we get a list of every article an author has written - but how can I get the author's information - their name, avatar, etc.?
PS: boy the V2 documentation is sparse...V1 was much better...
Append the query parameter _embed in your API URL
Embedding is triggered by setting the _embed query parameter on the request. This will then include embedded resources under the _embedded key adjacent to the _links key in JSON file... as showed in http://v2.wp-api.org/reference/links.html
Examples:
http://demo.wp-api.org/wp-json/wp/v2/posts?_embed
http://demo.wp-api.org/wp-json/wp/v2/posts?filter%5Bposts_per_page%5D=10&page=1&_embed
Getting Author Name from JSON, and showing:
{{postItem._embedded.author[0].name}}
Getting Featured Image:
{{postItem._embedded['wp:featuredmedia'][0].source_url}}
Categories:
{{postItem._embedded['wp:term'][0][0].slug}}
{{postItem._embedded['wp:term'][0][1].slug}}
{{postItem._embedded['wp:term'][0][2].slug}}
{{postItem._embedded['wp:term'][0][3].slug}}
...
and Tags:
{{postItem._embedded['wp:term'][1][1].slug}}
{{postItem._embedded['wp:term'][1][2].slug}}
...
I think what you want is /wp-json/wp/v2/users/1
You should also find the direct url at _links > author > href
If I have some arbitrary JSON how can I do deep sets and gets on the nested properties using a slice of map keys and/or slice indexes?
For example, in the following excerpt from the JSON API example:
{
"data": [{
"type": "posts",
"id": "1",
"title": "JSON API paints my bikeshed!",
"links": {
"self": "http://example.com/posts/1",
"author": {
"self": "http://example.com/posts/1/links/author",
"related": "http://example.com/posts/1/author",
"linkage": { "type": "people", "id": "9" }
}
}
}]
}
I'd like to get the string "9" located at data.0.links.author.linkage.id using something like:
[]interface{}{"data",0,"links","author","linkage","id"}
I know the ideal way to do this is to create nested structs that map to the JSON object which I do for production code, but sometimes I need to do some quick testing which would be nice to do in Go as well.
You have stretchr/objx that provide a similar approach.
Example use:
document, _ := objx.FromJSON(json)
document.Get("path.to.field[0].you.want").Str()
However, unless you really don't know at all the structure of your JSON input ahead of time, this isn't the preferred way to go in golang…