YouTube Api for channel list - android

I am newer in youtube api,I need help for implementing youtube api in android. I have find one youtube api for getting all channel list on associated username https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername={USERNAME}&key={YOUR_API_KEY}. I have created 3 channels in my youtube account but above api is not getting response.
This is response for above api with valid username and api key
{
"kind": "youtube#channelListResponse",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/ewwRz0VbTYpp2EGbOkvZ5M_1mbo\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": []
}

Use it like this:
https://www.googleapis.com/youtube/v3/channels?part=statistics&id=channel_id&key=your_key
You can try your API request here: https://developers.google.com/youtube/v3/docs/channels/list#try-it
Request:
HTTP GET: GET https://www.googleapis.com/youtube/v3/channels?part=statistics&id={CHANNEL_ID}&key={YOUR_API_KEY}
Response (with id=UCt7iVnJwjBsof8IPLJHCTgQ):
{
"kind": "youtube#channelListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/WNxXCvycTyqTjTn9sLJ5toVjBRY\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/jijTuA_iWn2Kv9aRnqeAWNAcQ6I\"",
"id": "UCt7iVnJwjBsof8IPLJHCTgQ",
"statistics": {
"viewCount": "796662",
"commentCount": "20",
"subscriberCount": "257",
"hiddenSubscriberCount": false,
"videoCount": "126"
}
}
]
}
You can pass in a comma-separated list of Channel IDs for the id parameter. Because I only passed in one id, the first object of the items array will have the values you need. Get the object for the subscriberCount and videoCount values in the statistics dictionary for the data you want.

Related

JSON data - How to parse?

Suppose I have data in JSON. How can I parse the data so I can get the values of nested objects (e.g. kind, id and title)?
My JSON data is:
{
"kind": "youtube#playlistItemListResponse",
"items": [
{
"id": "UExkc1JWcGJNV19LSH",
"items":[
{
"title": "New Updates",
}
],
}],
}
Well you should remove all the commas since last items should not be followed by one.
So more like:
{
"kind": "youtube#playlistItemListResponse",
"items": [{
"id": "UExkc1JWcGJNV19LSH",
"items": [{
"title": "New Updates"
}]
}]
}
Other than that you can just use JSONObject lib and extract the value you need. For example to get the kind:
JSONObject jsonObj = new JSONObject(strInput);
String kind = jsonObj.getString("kind"); // kind now contains "youtube#playlistItemListResponse"
where strInput is the above json as a string.
More info: https://developer.android.com/reference/org/json/JSONObject

Different API hit result with AsyncTask and PostMan

I have a problem when I hit the backend API, I found a difference result on Postman and AsyncTask (httpPost). Why does it happen?
I use the multer-s3-transform nodejs plugin to upload the files into my backend API's, then stored on digitalocean spaces.
Below is a result from AsyncTask:
{
"fieldname":"user_photo",
"originalname":"IMG-20180308_0938_55321.jpg",
"encoding":"7bit",
"mimetype":"application/octet-stream",
"size":84289,
"bucket":"mycdn",
"key":"1e9440387181846f54bece8a5d95a8a9",
"acl":"public-read",
"contentType":"image/jpeg",
"metadata":null,
"location":"https://mycdn.sgp1.digitaloceanspaces.com/1e9440387181846f54bece8a5d95a8a9",
"etag":"\"91ff71e41380602dbc35c94100f88d80\""
}
And this is one from PostMan:
{
"fieldname": "user_photo",
"originalname": "my-photos.png",
"encoding": "7bit",
"mimetype": "image/png",
"transforms": [
{
"id": "or",
"size": 109955,
"bucket": "mycdn",
"key": "users/1520907984802.png",
"acl": "public-read",
"contentType": "image/png",
"metadata": null,
"location": "https://mycdn.sgp1.digitaloceanspaces.com/users/1520907984802.png",
"etag": "\"8e161cab4c516b5eb48c3c1c66987de9\""
}
]
}
My final question, why is the transforms array not showing up in my AsyncTask result?

Getting issue in get id from youtube API

I am trying to get Id from Youtube API in android app but unable to find
https://www.googleapis.com/youtube/v3/channels?part=id&forUsername={username}&key={YOUR_API_KEY}
But getting this response:
{
"kind": "youtube#channelListResponse",
"etag": "\"sNu6csVZt536JdlmpOxN9WQSd8U/ewwRz0VbTYpp2EGbOkvZ5M_1mbo\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": []
}
I have also tried with this
https://www.googleapis.com/youtube/v3/channels?part=id%2CcontentDetails&mine=true&key={YOUR_API_KEY}
But a response is below:
{
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "authorizationRequired",
"message": "The request uses the \u003ccode\u003emine\u003c/code\u003e parameter but is not properly authorized.",
"locationType": "parameter",
"location": "mine"
}
],
"code": 401,
"message": "The request uses the \u003ccode\u003emine\u003c/code\u003e parameter but is not properly authorized."
}
}
make sure you are logged-in with OAuth when performing these calls and if you're going to parse the JSON response to look for the id, it's found in items.id
Tried this with Channels.list Try-it and I got correct response:
/**
* API response
*/
{
"kind": "youtube#channelListResponse",
"etag": "\"VPWTmrH7dFmi4s1RqrK4tLejnRI/X6OHzHqUUEu1okILXdfdfBbUxU\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"VPWTmrH7dFmi4s1RqrK4tLejfdf/Qw3dXynuD_IdfB1LMKjSeiDI\"",
"id": "UCTjdfopNLdfd5yXVv93Ww"
}
]
}

Android Studio and Youtube API Subscriber count?

I'm trying to insert into my app the number of subscribers and views from a channel on YouTube. How do I do that?
I've already setup the YouTube API and gotten my API Key.
I also have the URL that gives me the code below.
How do I turn this:
{
"kind": "youtube#channelListResponse",
"etag": "REMOVED",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "REMOVED",
"id": "REMOVED",
"statistics": {
"viewCount": "13398211",
"commentCount": "28",
"subscriberCount": "182758",
"hiddenSubscriberCount": false,
"videoCount": "84"
}
}
]
}
this is the request you need:
YouTube youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), null).setApplicationName("yourAppName").build();
YouTube.Channels.List channelListRequest = youTube.channels().list("statistics");
channelListRequest.setKey(DEVELOPER_KEY);
channelListRequest.setId(channelID);
channelListRequest.setFields("items/statistics(viewCount, subscriberCount)");
ChannelListResponse channelListResponse = channelListRequest.execute();
Channel channel = channelListResponse.getItems().get(0);
at this point you have the Channel object which contains the data you need. You can easly get the data from this object.
BigInteger viewCount = channel .getStatistics().getViewCount();
BigInteger subscriberCount = channel.getStatistics().getSubscriberCount();

same fql(facebook Query Language) shows different result in graph explorer and embedded in javascript code

I am developing hybrid app using cordova, app is intergated with facebook for which i used android SDK.
I need uid of friends of user, for I am using following fql
SELECT name,uid
FROM user
WHERE uid IN (SELECT target_id
FROM connection
WHERE source_id=me() and is_following=1)
ORDER BY name Asc
which is showing different uid in graph API Explorer and in logcat(android ide)
result in graph API Explorer
{
"data": [
{
"name": "Bharata Dumbo",
"uid": "817899964906568"
},
{
"name": "Deendayal Sharma",
"uid": "807134486015575"
},
{
"name": "Indravadan Intwala",
"uid": "813727452007073"
},
{
"name": "Manisha Parmar",
"uid": "10205158153335480"
},
{
"name": "Nitin Shah",
"uid": "1260451067"
},
{
"name": "Nitin Shah",
"uid": "100005623513169"
},
{
"name": "Smita Vora",
"uid": "323986007788625"
}
]
}
where as result in logcat::
Response getPageLike: `{"data":[{"uid":"100000597166472","name":"Bharata Dumbo"},{"uid":"792885570773800","name":"Deendayal Sharma"},{"uid":"813635845349567","name":"Indravadan Intwala"},{"uid":"10204471863338659","name":"Manisha Parmar"},{"uid":"1260451067","name":"Nitin Shah"},{"uid":"100005623513169","name":"Nitin Shah"},{"uid":"316474181873141","name":"Smita Vora"}]}`
Probably your app is a Graph API >=v2.0 app, that means it uses app-scoped ids instead of global ids as with v1.0.
The Graph Explorer sometimes inherently uses v1.0 (global ids respectively), even if another version is selected from the pulldown.
See
https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api

Categories

Resources