javascript - 如何确定用户是否订阅了 youtube channel

标签 javascript jquery iframe youtube youtube-api

我的页面上有 youtube 订阅按钮 (iframe)。有什么办法可以知道访问该站点的用户是否已订阅? 如果那不可能,也许有办法知道正在查看网站的某种用户 ID?

我发现当用户订阅时有一个属性

data-is-subscribed="true" 

对于按钮元素,但由于它来自 youtube 域,我无法以编程方式访问(至少我没有找到如何访问)iframe 源。

Blocked a frame with origin https://<my host ip> from accessing a frame with
origin https://<target host ip>. Protocols, domains, and ports must match.

谢谢

最佳答案

有两种方法可以检索用户的订阅:

  • To request a feed of the currently logged-in user's subscriptions, send a GET request to the following URL. Note: For this request, you must provide an authorization token, which enables YouTube to verify that the user authorized access to the resource.

https://gdata.youtube.com/feeds/api/users/default/subscriptions?v=2

*To request a feed of another user's subscriptions, send a GET request to the following URL. Note that this request does not require user authorization.

https://gdata.youtube.com/feeds/api/users/userId/subscriptions?v=2

在上面的 URL 中,您应该将文本 userId 替换为用户的 YouTube 用户 ID。为了向后兼容,API 还支持指定用户的 YouTube 用户名。

从这里您可以获得列表或空响应,这意味着用户没有订阅 channel 。您可以使用该列表来过滤他们是否已订阅。

关于javascript - 如何确定用户是否订阅了 youtube channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37333373/

相关文章:

java - Selenium WebDriver——XPath

javascript - 当子组件调用方法时,父引用为 null - ReactJS

javascript - 替换 CSS :hover with jQuery

javascript - 用于获取具有特定属性和类的所有标签的选择器

javascript - 如何在 iframe 中跟踪用户

javascript - HTML,Javascript : difference between an ajax call and changing the source of an iframe

javascript - 使用parents(),与Jquery中的$(this)函数最接近

javascript - 如何在 Firefox 中使用 "Start"和 "End"在 iframe 中选择范围,例如来自输入元素的 "selectionStart"

javascript - Vue.js:动态计算子组件

javascript - 输入字段清除按钮导致模糊事件 - 如何避免