0
我正在開發一個應用程序,用戶可以在其中訂閱我應用程序本身的各種頻道。所以要保存api請求,我想知道用戶是否已經訂閱了YouTube頻道。雖然研究,我發現一些代碼,修改了我的要求:查找用戶是否使用Youtube數據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
}
}
在執行我的代碼響應值始終不爲空是否用戶已經訂閱或沒有。可有人建議我該怎麼辦?