0
I’m not very suited to Youtube Api V3. But I watched a google Developers live where the google operator shows how to list the activity of a particular channel. Based on that I executed via GET
at the following address:
https://www.googleapis.com/youtube/v3/activities?part=snippet&channelId=UCaNLpnBnxEeQGfEym8bUr-g&maxResults=1&key={SUA_KEY_DE_DESENVOLVIMENTO}
and he returned this code to me. But this code I’m not getting to do Parse in json on it, because it starts with { ... }
and not the pattern that in the case would be nome_do_obj:{ ... }
, but being that { ... }
no beginning of object definition. I used the code:
NOTE: I used the https://www.nuget.org/packages/Newtonsoft.Json/
to decipher the code:
using using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public string TentarDecifrar(string textoJson, string key, string value){
JObject jsonData = new JObject(JObject.Parse(textoJson));
return jsonData[key][value];
}
But since the first object has no name/identification it returns NullOperationException
when I execute
void Main(){ MessageBox.Show(TentarDecifrar(CONTEUDO_EM_JSON_QUE_O_YOUTUBE_DATA_API_ME_RETORNA, "items", "description"));}
In case when I consulted the Jobject would be
jsonData[""]["items"]["description"]
/* no caso onde está [""] é onde aparece o objeto que não possui identificação ,ou seja:
{ <= nesta linha
"kind": "youtube#activityListResponse",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/HzaV00F-8u901Ma6Odl2HflceQE\"",
"nextPageToken": "CAEQAA", ... }
*/
I want to get the key items
and the value for example description
, where the variable CONTEUDO_EM_JSON_QUE_O_YOUTUBE_DATA_API_ME_RETORNA
is equal to:
{
"kind": "youtube#activityListResponse",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/HzaV00F-8u901Ma6Odl2HflceQE\"",
"nextPageToken": "CAEQAA",
"pageInfo": {
"totalResults": 6,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#activity",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/yikeFjK_8QolzIG4MyBtbexRdjs\"",
"id": "VTE0NDU3ODg1NTYxMzk4MjAyMjI2NDc2OTY=",
"snippet": {
"publishedAt": "2015-10-25T15:55:56.000Z",
"channelId": "UCaNLpnBnxEeQGfEym8bUr-g",
"title": "Minecraft - MiniGames # 1",
"description": "Todo canal de gamer tem que ter minecraft né ? haha\n\nPag: www.facebook.com/franporfirio98",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/6AzmgmtHTGY/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/6AzmgmtHTGY/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/6AzmgmtHTGY/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/6AzmgmtHTGY/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/6AzmgmtHTGY/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "Fran Gamer",
"type": "upload"
}
}
]
}
In short... I wanted to develop an application in Winforms so that I could see the youtube api v3 and it returns in json with the data of the last video sent from that particular channel. Even that I still have doubts between Json and Yaml.
erred in
var snipper = item["snippet"];
Cannot Applying with [] to an Expression of type Object`– FRNathan13
puts the whole code here
– Bruno Piovan
http://prntscr.com/91p33u
– FRNathan13
ah ta i erred! placed foreach(Object ...) is foreach(var ...)
– FRNathan13
Look at your third line, it’s with Object... switch to var :)
– Bruno Piovan
I read so fast
– FRNathan13
That’s it! It happens! :)
– Bruno Piovan
thanks so much! because as Youtube Api v2 ended for the platform . NET so I was 0/ desperate for a method to solve the problem. : )
– FRNathan13
is and in case the
type
is not equal toupload
?– FRNathan13
http://prntscr.com/91p6t3
– FRNathan13
Do you want to do q? filter items where type equals upload only?
– Bruno Piovan
well yes,.......
– FRNathan13
edited the answer, it’s the simplest way... you could use LINQ too, but I think it’s unnecessary, but if you want to read about it, here it goes http://www.newtonsoft.com/json/help/html/QueryingLINQtoJSON.htm
– Bruno Piovan
Okay I’ll try this!
– FRNathan13
Pivoan! Can you help me read this json now? http://powdertoy.co.uk/Browse/Comments.json?ID=1681176&Start=0&Count=20 is a comment system generated from a simulator, but I want to put it in xml and I cannot.!
– FRNathan13
ta aí! http://s13.postimg.org/oo4rvhrfb/Capture.png
– Bruno Piovan