I am using java in programming with youtube api library. as written in title I want to get source link for youtube channel logo (image in top left corner beside channel name). for example: http://www.youtube.com/user/NationalGeographic here it's my try:
YouTubeService service = new YouTubeService("NationalGeographic");
String feedUrl = http://gdata.youtube.com/feeds/api/users/NationalGeographic/uploads;
VideoFeed videoFeed = service.getFeed(new URL(feedUrl), VideoFeed.class);
String title = videoFeed.getTitle().getPlainText();
so I got channel name but I can't get channel logo. please any help.
With the new v3 API, you can get it by listing the channel:
https://developers.google.com/youtube/v3/docs/channels/list
They retrieve the logo in different sizes
Here is the output of Joe Rogan Experience :
{
"kind": "youtube#channelListResponse",
"etag": "\"Fznwjl6JEQdo1MGvHOGaz_YanRU/_RZUfBijoiFpUwyyBzSuSJbKOi8\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"Fznwjl6JEQdo1MGvHOGaz_YanRU/zhDVFVQYUTKigur2_WU6BMjm2Qo\"",
"id": "UCzQUP1qoWDoEbmsQxvdjxgQ",
"snippet": {
"title": "PowerfulJRE",
"description": "The Joe Rogan Experience podcast",
"customUrl": "joerogan",
"publishedAt": "2013-01-12T01:40:14.000Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/a/AGF-l78OfG5OxzCfyyoFqw-dKeiFNGzTIT4YgpMK4Q=s88-c-k-c0xffffffff-no-rj-mo",
"width": 88,
"height": 88
},
"medium": {
"url": "https://yt3.ggpht.com/a/AGF-l78OfG5OxzCfyyoFqw-dKeiFNGzTIT4YgpMK4Q=s240-c-k-c0xffffffff-no-rj-mo",
"width": 240,
"height": 240
},
"high": {
"url": "https://yt3.ggpht.com/a/AGF-l78OfG5OxzCfyyoFqw-dKeiFNGzTIT4YgpMK4Q=s800-c-k-c0xffffffff-no-rj-mo",
"width": 800,
"height": 800
}
},
"localized": {
"title": "PowerfulJRE",
"description": "The Joe Rogan Experience podcast"
}
},
"contentDetails": {
"relatedPlaylists": {
"uploads": "UUzQUP1qoWDoEbmsQxvdjxgQ",
"watchHistory": "HL",
"watchLater": "WL"
}
},
"statistics": {
"viewCount": "1783605586",
"commentCount": "0",
"subscriberCount": "7180000",
"hiddenSubscriberCount": false,
"videoCount": "2305"
}
}
]
}
I don't think you can get it with the v2 API (although I hope you can), but the link structure for these images is somewhat similar:
http://i2.ytimg.com/i/UHW94eEFW7hkUMVaZz4eDg/1.jpg?v=d69778
http://i4.ytimg.com/i/7-BWdwziR8LozMCBD1Ei7w/1.jpg?v=d8170b
Wonder where those ids come from...
Related
I want to get the value of description in Title(textview)
Here is json :
{
"kind": "youtube#videoListResponse",
"etag": "HCuE2tlv6pL-pkBXCa6_p5vmZGc",
"items": [
{
"kind": "youtube#video",
"etag": "yDMBbFsSFuOYTDqCooA3YoiGb_0",
"id": "omHuhbtWIY0",
"snippet": {
"publishedAt": "2022-03-11T12:40:37Z",
"channelId": "UCIjzLN8bj7Qv5daGJqj9rHA",
"title": "HTML creator master",
"description": "App Link - https://technical-studio-develop-7a3b1.web.app/\n\n00:00 Intro\n00:08 Introducing to app\n\n\n-----------------------------------------------\nCopyright Disclaimer under Section 107 of the copyright act 1976, allowance is made for fair use for purposes such as criticism, comment, news reporting, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favour of fair use.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/omHuhbtWIY0/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/omHuhbtWIY0/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/omHuhbtWIY0/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/omHuhbtWIY0/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/omHuhbtWIY0/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "Dream Programmers",
"categoryId": "22",
"liveBroadcastContent": "none",
"localized": {
"title": "HTML creator master",
"description": "App Link - https://technical-studio-develop-7a3b1.web.app/\n\n00:00 Intro\n00:08 Introducing to app\n\n\n-----------------------------------------------\nCopyright Disclaimer under Section 107 of the copyright act 1976, allowance is made for fair use for purposes such as criticism, comment, news reporting, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favour of fair use."
}
}
}
],
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
}
}
My Java code:
_youtube_data_request_listener = new RequestNetwork.RequestListener() {
#Override
public void onResponse(String _param1, String _param2, HashMap<String, Object> _param3) {
final String _tag = _param1;
final String _response = _param2;
final HashMap<String, Object> _responseHeaders = _param3;
/*
= new Gson().fromJson("", new TypeToken<ArrayList<String>>(){}.getType());
*/
_processdialog(false, "");
ytData = new HashMap<>();
ytData = new Gson().fromJson(_response, new TypeToken<HashMap<String, Object>>(){}.getType());
title.setText(ytData.get("items")[].snippet.title);
ytData.clear();
}
#Override
public void onErrorResponse(String _param1, String _param2) {
final String _tag = _param1;
final String _message = _param2;
}
};
I want to get the value in title and set it in title textview.
I using JOLT to transform and extract a URL of an object, but it's only the URL slug. Is it possible to concatenate a static string to that slug to have a full URL?
The current output is:
{
"title" : "Where is deleted user data visible, and for how long is it there?",
"externalId" : "where_is_deleted_user_data_visible__and_for_how_lo",
"summary" : "Deleted user data is stored in LP and visible for 13 months following deletion.",
"detail" : "<p>Deleted user data is stored in LP and visible for <strong>13 months following deletion.</strong></p>\n<p>Deleted agents are displayed with a '(deleted)' indicator in the Open Conversations, All Conversations, Web History lists, and the Conversation History widget.</p>\n<object type=\"application/kenticocloud\" data-type=\"item\" data-rel=\"component\" data-codename=\"n6fdd091f_fcb5_012a_8745_c1671c268e6b\"></object>\n<p>Filter by deleted agents is available in the Open Conversations, All Conversations, and web history lists.</p>\n<p>In the visitor conversation window, the name of the deleted agent will be displayed in the window header (with no indication that they have been deleted).</p>\n<p>The LP user limit '<code>collections.maxElements</code>' will not count the number of deleted users in the total.</p>\n<object type=\"application/kenticocloud\" data-type=\"item\" data-rel=\"component\" data-codename=\"n3f1dea42_ac2e_01c6_cbd6_3f802d4e8fb3\"></object>",
"url" : "faqs-data-reporting1.html"
}
And the expected output is:
{
"title" : "Where is deleted user data visible, and for how long is it there?",
"externalId" : "where_is_deleted_user_data_visible__and_for_how_lo",
"summary" : "Deleted user data is stored in LP and visible for 13 months following deletion.",
"detail" : "<p>Deleted user data is stored in LP and visible for <strong>13 months following deletion.</strong></p>\n<p>Deleted agents are displayed with a '(deleted)' indicator in the Open Conversations, All Conversations, Web History lists, and the Conversation History widget.</p>\n<object type=\"application/kenticocloud\" data-type=\"item\" data-rel=\"component\" data-codename=\"n6fdd091f_fcb5_012a_8745_c1671c268e6b\"></object>\n<p>Filter by deleted agents is available in the Open Conversations, All Conversations, and web history lists.</p>\n<p>In the visitor conversation window, the name of the deleted agent will be displayed in the window header (with no indication that they have been deleted).</p>\n<p>The LP user limit '<code>collections.maxElements</code>' will not count the number of deleted users in the total.</p>\n<object type=\"application/kenticocloud\" data-type=\"item\" data-rel=\"component\" data-codename=\"n3f1dea42_ac2e_01c6_cbd6_3f802d4e8fb3\"></object>",
"url" : "https://www.static-url.com/faqs-data-reporting1.html"
}
The JOLT Spec is:
[
{
"operation": "shift",
"spec": {
"item": {
"system": {
"name": "title",
"codename": "externalId"
},
"elements": {
"short_answer": {
"value": ["summary"]
},
"long_answer": {
"value": "detail"
}
}
},
"modular_content": {
"*": {
"elements": {
"permalink": {
"value": "url"
}
}
}
}
}
}
]
The JSON input is:
{
"item": {
"system": {
"id": "6e55g261aee-34d9-47be-8830-145ec71b564f",
"name": "Where is deleted user data visible, and for how long is it there?",
"codename": "where_is_deleted_user_data_visible__and_for_how_lo",
"language": "en-US",
"type": "faq",
"collection": "default",
"sitemap_locations": [],
"last_modified": "2022-04-11T15:32:08.0844256Z",
"workflow_step": "published"
},
"elements": {
"question": {
"type": "text",
"name": "Question",
"value": "Where is deleted user data visible, and for how long is it there?"
},
"short_answer": {
"type": "text",
"name": "Bot Teaser Answer",
"value": "Deleted user data is stored in LP and visible for 13 months following deletion."
},
"long_answer": {
"type": "rich_text",
"name": "Full Answer",
"images": {},
"links": {},
"modular_content": [
"n6fdd091f_fcb5_012a_87545_c1671c268e6b",
"n3f1dea42_ac2e_01cdf6_cbd6_3f802d4e8fb3"
],
"value": "<p>Deleted user data is stored in LP and visible for <strong>13 months following deletion.</strong></p>\n<p>Deleted agents are displayed with a '(deleted)' indicator in the Open Conversations, All Conversations, Web History lists, and the Conversation History widget.</p>\n<object type=\"application/kenticocloud\" data-type=\"item\" data-rel=\"component\" data-codename=\"n6fdd091f_fcb5_012a_8745_c1671c268e6b\"></object>\n<p>Filter by deleted agents is available in the Open Conversations, All Conversations, and web history lists.</p>\n<p>In the visitor conversation window, the name of the deleted agent will be displayed in the window header (with no indication that they have been deleted).</p>\n<p>The LP user limit '<code>collections.maxElements</code>' will not count the number of deleted users in the total.</p>\n<object type=\"application/kenticocloud\" data-type=\"item\" data-rel=\"component\" data-codename=\"n3f1dea42_ac2e_01c6_cbd6_3f802d4e8fb3\"></object>"
},
"faq_page": {
"type": "modular_content",
"name": "This FAQ item's FAQ page(s)",
"value": [
"data___reporting_9658b36"
]
},
"related_article": {
"type": "modular_content",
"name": "Related article",
"value": []
}
}
},
"modular_content": {
"data___reporting_9658b36": {
"system": {
"id": "9658bddf362-735b-47fd3c-9232-26de14835d8f",
"name": "Data & Reporting",
"codename": "data___reporting_9658b36",
"language": "en-US",
"type": "kc_faqs",
"collection": "default",
"sitemap_locations": [],
"last_modified": "2022-04-13T16:18:12.2538592Z",
"workflow_step": "published"
},
"elements": {
"pagename": {
"type": "text",
"name": "Title",
"value": "Data & Reporting"
},
"faq_items": {
"type": "modular_content",
"name": "FAQ Items",
"value": [
"how_do_i_find_chats_that_only_contain_private_mess",
"how_do_i_understand_why_a_chat_ended_",
"how_do_i_change_the_email_address_for_scheduled_re",
"how_do_i_retrieve_data_that_has_been_masked_",
"where_is_deleted_user_data_visible__and_for_how_lo"
]
},
"related_articles": {
"type": "modular_content",
"name": "Related Articles",
"value": []
},
"permalink": {
"type": "url_slug",
"name": "URL slug",
"value": "faqs-data-reporting1.html"
},
"redirects": {
"type": "text",
"name": "redirects",
"value": "faqs-data-reporting1.html"
}
}
},
"n3f1dea42_ac2e_01c6_cbd6_3f802d4e8fb3": {
"system": {
"id": "3f1dea42-ac2e-01c6-cbd6-3f802d4e8fb3",
"name": "3f1dea42-ac2e-01c6-cbd6-3f802d4e8fb3",
"codename": "n3f1dea42_ac2e_01c6_cbd6_3f802d4e8fb3",
"language": "en-US",
"type": "contentbox",
"collection": "default",
"sitemap_locations": [],
"last_modified": "2022-04-11T15:32:08.0844256Z"
},
"elements": {
"type": {
"type": "multiple_choice",
"name": "Type",
"value": [
{
"name": "Warning (orange)",
"codename": "warning"
}
]
},
"notice_text": {
"type": "rich_text",
"name": "Text",
"images": {},
"links": {},
"modular_content": [],
"value": "<p>A user who joined a chat and then was deleted won’t be reflected as deleted in the history.</p>"
}
}
},
"n6fdd091f_fcb5_012a_8745_c1671c268e6b": {
"system": {
"id": "6fdd091f-fcb5-012a-8745-c1671c268e6b",
"name": "6fdd091f-fcb5-012a-8745-c1671c268e6b",
"codename": "n6fdd091f_fcb5_012a_8745_c1671c268e6b",
"language": "en-US",
"type": "contentbox",
"collection": "default",
"sitemap_locations": [],
"last_modified": "2022-04-11T15:32:08.0844256Z"
},
"elements": {
"type": {
"type": "multiple_choice",
"name": "Type",
"value": [
{
"name": "Notice (blue)",
"codename": "notice"
}
]
},
"notice_text": {
"type": "rich_text",
"name": "Text",
"images": {},
"links": {},
"modular_content": [],
"value": "<p>Before deleting a user, ensure that the agent doesn’t own any open conversations (if so, these conversations should be transferred to the queue) and that the user is logged out of LP.</p>"
}
}
}
}
}
Any option to add the static URL link to the output?
You can add a modify spec with concat function after the current shift transformation spec such as
{
"operation": "modify-overwrite-beta",
"spec": {
"url": "=concat('https://www.static-url.com/',#(1,&))" // first argument is static, and the second one is dynamic(directly inherited from the current value of "url") content
}
}
I have a mongo document of orderData. And i want to apply some aggregation on it. I have projects and on the basis of projects i want to group my order information.
But problem is that my orders will be in two currencies against one customer and i want to show both currencies total in my UI.
[{
"orderNumber": "abc#1",
"project": "project1",
"cashCollection": {
"iso": "USD",
"total": 100
}
},
{
"orderNumber": "abc#2",
"project": "project1",
"cashCollection": {
"iso": "EUR",
"total": 100
}
},
{
"orderNumber": "abc#3",
"project": "project1",
"cashCollection": {
"iso": "USD",
"total": 100
}
}
]
And i want response like that.
{
"project": "project1",
"totalCashCollection": [{
"iso": "USD",
"total": 200
},
{
"iso": "AUD",
"total": 100
}
]
}
I want to fetch this result via mongo template. And i am stuck on it . can any body help???
Below is the code snippet for the utility which I've used to fetch data.
Below are sample JSON in which I have to fetch the value of Other/Vehicle/Properties, but I'm getting an error message.
Please suggest what things I need to add to the utility?
I need to get the value of Other/Vehicle/Properties.
Please suggest what things I need to change in the Utility so that nested property also fetched from JSON.
public class TestUtil {
public static JSONObject responsejson;
public static String getValueByJPath(JSONObject responsejson, String jpath){
Object obj = responsejson;
for(String s : jpath.split("/"))
if(!s.isEmpty())
if(!(s.contains("[") || s.contains("]")))
obj = ((JSONObject) obj).get(s);
else if(s.contains("[") || s.contains("]"))
obj = ((JSONArray) ((JSONObject) obj).get(s.split("\\[")[0])).get(Integer.parseInt(s.split("\\[")[1].replace("]", "")));
return obj.toString();
}
}
JSON Format:
{
"coverageEndDate": "02/28/2019",
"coverageStartDate": "03/01/2018",
"coverageType": "Personal",
"error": {
"code": 0,
"message": ""
},
"firstName": "Ronnie",
"insuredItems": {
"other": [{
"coverageEndDate": "02/28/2019",
"coverageStartDate": "03/01/2018",
"description": "Hunter Marin Passage 450",
"id": 14
}],
"properties": [{
"address": "31 LAKEWOOD RD, WEST BEND, WI 53090",
"coverageEndDate": "02/28/2019",
"coverageStartDate": "03/01/2018",
"deductible": 5000,
"description": "31 LAKEWOOD RD, WEST BEND, WI 53090",
"id": "113",
"limit": 2000000
}],
"vehicles": [{
"coverageEndDate": "02/28/2019",
"coverageStartDate": "03/01/2018",
"deductible": "$500 Comprehensive\n$500 Collision",
"description": "2016 Ford Explorer",
"id": "126",
"limit": "$100,000",
"make": "FORD",
"model": "EXPLORER",
"transportationExpense": "$30 per day and $900 max",
"vin": "1G1FA1E38F2131121",
"year": 2016
}, {
"coverageEndDate": "02/28/2019",
"coverageStartDate": "06/18/2018",
"deductible": "$500 Comprehensive\n$500 Collision",
"description": "2017 Dodg Durango",
"id": "127",
"limit": "$100,000",
"make": "DODG",
"model": "DURANGO",
"transportationExpense": "$30 per day and $900 max",
"vin": "2G1XER366DE4DE3H5",
"year": 2007
}]
},
"lastName": "James Dio",enter code here
"policyNumber": "5519930"
}
Use normal parser from jackson lib by this example
Good afternoon dear Stack-overflowees!
I've got the following youtube response for a query for videos from a HTTPRequest:
null{ "kind": "youtube#searchListResponse", "etag": "\"5g01s4- S2b4VpScndqCYc5Y-8k/MnX_l4A0-CoCz7AqTuwYbZZ8Eos\"", "nextPageToken": "CAoQAA","regionCode": "NL", "pageInfo": { "totalResults": 1000000, "resultsPerPage": 10 }, "items": [ { "kind": "youtube#searchResult", "etag": "\"5g01s4-wS2b4VpScndqCYc5Y-8k/3x0aJRM9h33YMFvqksUj6alhFqU\"", "id": { "kind": "youtube#video", "videoId": "_nws2egRR1w" }, "snippet": { "publishedAt": "2015-06-26T19:00:00.000Z", "channelId": "UCY30JRSgfhYXA6i6xX1erWg", "title": "GODS IN REAL LIFE", "description": "Thank you to Smite for sponsoring this video! SMITE is an online battleground where the Gods of Old wage war in the name of conquest, glory, and most of all, ...", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/_nws2egRR1w/default.jpg", "width": 120, "height": 90 }, "medium": { "url": "https://i.ytimg.com/vi/_nws2egRR1w/mqdefault.jpg", "width": 320, "height": 180 }, "high": { "url": "https://i.ytimg.com/vi/_nws2egRR1w/hqdefault.jpg", "width": 480, "height": 360 } }, "channelTitle": "Smosh", "liveBroadcastContent": "none" } }, { "kind": "youtube#searchResult", "etag": "\"5g01s4-wS2b4VpScndqCYc5Y-8k/K_ZgSkXsMidzJqa-m1IoLJU6UBE\"", "id": { "kind": "youtube#video", "videoId": "UiPZFPYhmzs" }, "snippet": { "publishedAt": "2014-03-22T18:02:28.000Z", "channelId": "UCo_IB5145EVNcf8hw1Kku7w", "title": "Game Theory: Are SMITE's Goddesses TOO SEXY?", "description": "Become a Theorist! ▻ http://.com/mrd2ntg SMITE is a MOBA with fast-paced action, terrific game modes, and well-endowed goddesses. In fact, the ...", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/UiPZFPYhmzs/default.jpg", "width": 120, "height": 90 }, "medium": { "url": "https://i.ytimg.com/vi/UiPZFPYhmzs/mqdefault.jpg", "width": 320, "height": 180 }, "high": { "url": "https://i.ytimg.com/vi/UiPZFPYhmzs/hqdefault.jpg", "width": 480, "height": 360 } }, "channelTitle": "The Game Theorists", "liveBroadcastContent": "none" } }, { "kind": "youtube#searchResult", "etag": "\"5g01s4-wS2b4VpScndqCYc5Y-8k/wITeN0CQk1zT1C9k6Pm4BpvN3Jk\"", "id": { "kind": "youtube#video", "videoId": "5mVYnfJS73U" }, "snippet": { "publishedAt": "2016-01-05T14:00:01.000Z", "channelId": "UCLB_2GSFGa4Unb5fjq49SOw", "title": "SMITE Cinematic Trailer - 'To Hell & Back'", "description": "Welcome to SMITE, the online Battleground of the Gods. Play free at www.SmiteGame.com and seize victory in intense battles of strategic action, each fueled by ...", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/5mVYnfJS73U/default.jpg", "width": 120, "height": 90 }, "medium": { "url": "https://i.ytimg.com/vi/5mVYnfJS73U/mqdefault.jpg", "width": 320, "height": 180 }, "high": { "url": "https://i.ytimg.com/vi/5mVYnfJS73U/hqdefault.jpg", "width": 480, "height": 360 } }, "channelTitle": "SMITE by Hi-Rez Studios", "liveBroadcastContent": "none" } }, { "kind": "youtube#searchResult", "etag": "\"5g01s4-wS2b4VpScndqCYc5Y-8k/e5NJ3_X-R_m5PEqxSbN26lIAsJo\"", "id": { "kind": "youtube#video", "videoId": "Chu1XqxoQio" }, "snippet": { "publishedAt": "2015-07-16T17:03:55.000Z", "channelId": "UCWeg2Pkate69NFdBeuRFTAw", "title": "LE DIEU DE LA LOOSE ! (Smite)", "description": "On a pas l'habitude de jouer à ce genre de jeux, mais ça change un peu ! Par contre on se fait défoncer ça ça changera jamais :') Les règles : 10 Dieux ...", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/Chu1XqxoQio/default.jpg", "width": 120, "height": 90 }, "medium": { "url": "https://i.ytimg.com/vi/Chu1XqxoQio/mqdefault.jpg", "width": 320, "height": 180 }, "high": { "url": "https://i.ytimg.com/vi/Chu1XqxoQio/hqdefault.jpg", "width": 480, "height": 360 } }, "channelTitle": "SQUEEZIE", "liveBroadcastContent": "none" } }, { "kind": "youtube#searchResult", "etag": "\"5g01s4-wS2b4VpScndqCYc5Y-8k/j2Z6NrL6kZ7BqCqLC9T-iDIwVMo\"", "id": { "kind": "youtube#video", "videoId": "vAnVb_oBF7I" }, "snippet": { "publishedAt": "2014-06-07T19:00:02.000Z", "channelId": "UC-lHJZR3Gqxm24_Vd_AJ5Yw", "title": "3 HEROES, 3 QUESTIONS! - Smite: Tournament", "description": "Will they get good? Will Cry find love? Will they get a kill? Find out here!: http://ly/1p1xH05 http://youtu.be/lrXsGQO6Hrs I edited the first part of this video, Cry ...", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/vAnVb_oBF7I/default.jpg", "width": 120, "height": 90 }, "medium": { "url": "https://i.ytimg.com/vi/vAnVb_oBF7I/mqdefault.jpg", "width": 320, "height": 180 }, "high": { "url": "https://i.ytimg.com/vi/vAnVb_oBF7I/hqdefault.jpg", "width": 480, "height": 360 } }, "channelTitle": "PewDiePie", "liveBroadcastContent": "none" } }, { "kind": "youtube#searchResult", "etag": "\"5g01s4-wS2b4VpScndqCYc5Y-8k/9_S9Q9n9KHeFGuPeBIlxzFHp8hc\"", "id": { "kind": "youtube#video", "videoId": "CSFibeWqXaM" }, "snippet": { "publishedAt": "2015-08-02T16:01:42.000Z", "channelId": "UCLB_2GSFGa4Unb5fjq49SOw", "title": "SCL Spring Split Week 1 Day 4", "description": "", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/CSFibeWqXaM/default_live.jpg", "width": 120, "height": 90 }, "medium": { "url": "https://i.ytimg.com/vi/CSFibeWqXaM/mqdefault_live.jpg", "width": 320, "height": 180 }, "high": { "url": "https://i.ytimg.com/vi/CSFibeWqXaM/hqdefault_live.jpg", "width": 480, "height": 360 } }, "channelTitle": "SMITE by Hi-Rez Studios", "liveBroadcastContent": "live" } }, { "kind": "youtube#searchResult", "etag": "\"5g01s4-wS2b4VpScndqCYc5Y-8k/_HsRcEb5SgSrO7KDYGVcWnM-IyE\"", "id": { "kind": "youtube#video", "videoId": "4I7kDcRdM2Q" }, "snippet": { "publishedAt": "2012-06-02T07:31:19.000Z", "channelId": "UCTy_oLoGaQnV7LeiOkxx3qw", "title": "SMITE Gameplay (Part 1) - First Look HD", "description": "http://mmohuts.com/preview/smite for SMITE reviews, videos, screenshots and more. SMITE is a third person MOBA published by Hi-Rez Studios . MMOHuts has ...", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/4I7kDcRdM2Q/default.jpg", "width": 120, "height": 90 }, "medium": { "url": "https://i.ytimg.com/vi/4I7kDcRdM2Q/mqdefault.jpg", "width": 320, "height": 180 }, "high": { "url": "https://i.ytimg.com/vi/4I7kDcRdM2Q/hqdefault.jpg", "width": 480, "height": 360 } }, "channelTitle": "MMOHuts", "liveBroadcastContent": "none" } }, { "kind": "youtube#searchResult", "etag": "\"5g01s4-wS2b4VpScndqCYc5Y-8k/NFvQY8IZQap1sIr8ovsni7HsLAI\"", "id": { "kind": "youtube#video", "videoId": "OwAC1VD1608" }, "snippet": { "publishedAt": "2015-04-12T23:00:00.000Z", "channelId": "UCda7Fl9Q4wmqDqASRDqrVbA", "title": "COCIELO TESTE, O CRACUDO - DetonaTHOR Smite [2/2]", "description": "BAIXE E JOGUE SMITE DE GRAÇA: http://lup.vc/JogueSmite_Muca PARTE 1 DO EVENTO: https://youtu.be/DHtOrB63DD0 Instagram: ...", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/OwAC1VD1608/default.jpg", "width": 120, "height": 90 }, "medium": { "url": "https://i.ytimg.com/vi/OwAC1VD1608/mqdefault.jpg", "width": 320, "height": 180 }, "high": { "url": "https://i.ytimg.com/vi/OwAC1VD1608/hqdefault.jpg", "width": 480, "height": 360 } }, "channelTitle": "Muca Muriçoca", "liveBroadcastContent": "none" } }, { "kind": "youtube#searchResult", "etag": "\"5g01s4-wS2b4VpScndqCYc5Y-8k/_QFud2t95zRYczOqcudKnUHL4r8\"", "id": { "kind": "youtube#video", "videoId": "6q0uAevwQ2Q"
Only the first part is actually relevent, seeing as how the response starts off with a 'null'.
Now i've tried using the following code to parse the json using GSON.(result being the aforementioned JSON as a String.
JsonElement jelement = new JsonParser().parse(result);
JsonObject jobject = jelement.getAsJsonObject();
JsonArray jarray = jobject.getAsJsonArray("items");
However, Gson cannot work around the 'null' at the front of the json string. It converts the entire object in the first line not into a JsonElement but JsonNull.
Is there any way to try and get the array called 'items' from the string directly?
I've tried replacing the null with another word, i've tried several other things such as GsonBuilder.serializeNulls() and several other stackoverflow entried, yet I cannot work around this.
Any help/tips would be very much appreciated.
--edit--
following java code is used to call the api:
private String baseUrl = "https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&order=viewCount&q=";
String output;
String result = "";
URL url = new URL(this.baseUrl + q + "&type=video&key=" + key);
Gson gson = new Gson();
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json");
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
result += output;
}
System.out.println(result);
I would guess your'e result is initiated with null so "result+=output" will be null"output" cause a NullPointer results in "null" in "+" string concatenation. Think thats your problem. Either init it with empty String or check in your while loop for null.