Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Studio和Youtube API用户数?_Android_Youtube_Youtube Api - Fatal编程技术网

Android Studio和Youtube API用户数?

Android Studio和Youtube API用户数?,android,youtube,youtube-api,Android,Youtube,Youtube Api,我正试图在我的应用程序中插入YouTube上某个频道的订户数和浏览量。我该怎么做 我已经安装了YouTube API并获得了API密钥 我还有一个URL,它提供了下面的代码 我该如何扭转这种局面: { “种类”:“youtube#channelListResponse”, “etag”:“已删除”, “页面信息”:{ "总成绩":1,, “结果每页”:1 }, “项目”:[ { “种类”:“youtube频道”, “etag”:“已删除”, “id”:“已删除”, “统计”:{ “viewCo

我正试图在我的应用程序中插入YouTube上某个频道的订户数和浏览量。我该怎么做

我已经安装了YouTube API并获得了API密钥

我还有一个URL,它提供了下面的代码

我该如何扭转这种局面:

{
“种类”:“youtube#channelListResponse”,
“etag”:“已删除”,
“页面信息”:{
"总成绩":1,,
“结果每页”:1
},
“项目”:[
{
“种类”:“youtube频道”,
“etag”:“已删除”,
“id”:“已删除”,
“统计”:{
“viewCount”:“13398211”,
“commentCount”:“28”,
“subscriberCount”:“182758”,
“HiddenSuberCount”:false,
“videoCount”:“84”
}
}
]

}
这是您需要的请求:

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);
此时,您就拥有了包含所需数据的通道对象。您可以轻松地从该对象获取数据

BigInteger viewCount = channel .getStatistics().getViewCount();
BigInteger subscriberCount = channel.getStatistics().getSubscriberCount();

这将帮助您解析JSON字符串,并将值传递给构造函数