【问题标题】:Find whether user has subscribed youtube channel using Youtube data api使用 Youtube 数据 api 查找用户是否订阅了 youtube 频道
【发布时间】: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


    【解决方案1】:

    要检索用户已经订阅的频道,您可能需要尝试使用Activities: list 并将mine 参数设置为true。成功的请求将返回带有活动资源的响应正文:

    "contentDetails": {
        "subscription": {
          "resourceId": {
            "kind": string,
            "channelId": string,
          }
        }
    }
    

    contentDetails.subscription.resourceId.channelId 是 YouTube 用来唯一标识用户订阅的频道的 ID。

    【讨论】:

      猜你喜欢
      • 2013-09-29
      • 2014-05-15
      • 2016-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-01
      • 2014-09-19
      • 2013-01-29
      相关资源
      最近更新 更多