YouTube 数据 API v3 没有资源的唯一 ID [英] YouTube Data API v3 does not have unique IDs for resources

查看:23
本文介绍了YouTube 数据 API v3 没有资源的唯一 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我很困惑,而且看起来有点可笑.当我在数据 API 上执行两个不同的查询时(以 Activity列出端点作为概念证明)资源的id在请求之间是不同的.

This is befuddling me and seems a bit ludicrous. When I execute two different queries on the Data API (take the example request on the Activities List endpoint as a proof of concept) the id for resources are not the same between requests.

这是我第一个请求的活动资源:

Here's an activity resource from my first request:

{
    "kind": "youtube#activity",
    "etag": "\"RmznBCICv9YtgWaaa_nWDIH1_GM/uGfbHYfKHEFhxWYbbmVxyBbQvNk\"",
    "id": "VTE1MjI3NzQwODY5NDMzMzYyOTc5NjQ5Ng==",
    "snippet": {
        "publishedAt": "2018-04-03T16:48:06.000Z",
        "channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
        "title": "Google Summer of Code 2013 Mentor Summit",
        // ...
    }
    // ...
}

注意 id 值,根据 API 文档.

这是我的第二个请求:

{
    "kind": "youtube#activity",
    "etag": "\"RmznBCICv9YtgWaaa_nWDIH1_GM/dzIxWbnYZ3xx-1zi2VQ0V_f5PII\"",
    "id": "VTE1MjI3NzQwODY5NDYzMDM0OTg5MDAwMA==",
    "snippet": {
        "publishedAt": "2018-04-03T16:48:06.000Z",
        "channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
        "title": "Google Summer of Code 2013 Mentor Summit",
        // ...
    }
    // ...
}

对于相同的资源,id 是不同的.虽然前几个字符是相同的,但我尝试截断 id 但它仍然不是所有资源唯一的.

The id is different for the same resources. Although first few characters are the same, I've tried to truncate the id but it's still not unique for all resources.

我想知道 id 是否是唯一标识资源的事实上的方式.有没有人遇到过这个?这是正确的行为吗?如果 YouTube 提供的 id 不是这种方式,我如何唯一标识资源?我可以组合一个 hacky 解决方案,但这似乎不对.

I'm wondering if the id is the de facto way to uniquely identify resources. Has anyone run into this? Is this the proper behavior? How do I uniquely identify resources if the id that YouTube provides is not the way? I could put together a hacky solution, but this doesn't seem right.

很想听听想法.

推荐答案

我使用的解决方案是将活动发布日期的哈希值和频道 ID 附加在一起.这对我来说不太合适,但这是我采用的解决方案.

The solution I used was to take the hash of the publish date of the activity and the channel ID appended together. This does not sit well with me, but it's the solution I went with.

这篇关于YouTube 数据 API v3 没有资源的唯一 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆