【发布时间】:2017-06-23 05:58:16
【问题描述】:
我正在开发一个应用程序,用户可以在其中订阅我的应用程序本身的各种频道。因此,为了保存 api 请求,我想知道用户是否已经订阅了 youtube 频道。在研究时,我发现了一些代码并根据我的要求对其进行了修改:
static public boolean checkIfUserAlreadySubscribed(String channelyoutubeid) {
SubscriptionListResponse response = null;
try {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("part", "snippet,contentDetails");
parameters.put("forChannelId", channelyoutubeid);
parameters.put("mine", "true");
YouTube.Subscriptions.List subscriptionsListForChannelIdRequest = MainActivity
.mService.subscriptions().list(parameters.get("part").toString());
if (parameters.containsKey("forChannelId") && parameters.get("forChannelId") != "") {
subscriptionsListForChannelIdRequest.setForChannelId(parameters
.get("forChannelId").toString());
}
if (parameters.containsKey("mine") && parameters.get("mine") != "") {
boolean mine = (parameters.get("mine") == "true") ? true : false;
subscriptionsListForChannelIdRequest.setMine(mine);
}
response = subscriptionsListForChannelIdRequest.execute();
} catch (IOException e) {
e.printStackTrace();
}
if (response != null) {
//What should i do here
} else {
//whta should i pass
}
}
在执行我的代码时,无论用户是否订阅,响应值始终不为空。谁能建议我该怎么做??
【问题讨论】:
标签: android youtube-api youtube-data-api android-youtube-api