且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用*** API从***VideoFeed对象获取公共频道URL?

更新时间:2023-02-21 08:21:05

如果您想自己构建网址,那么***.com/user/USERNAME是一个非常安全的选择,但是我认为您想要的是链接rel ='alternate'

Well, the ***.com/user/USERNAME is a pretty safe bet if you want to construct the URL yourself, but I think what you want is the link rel='alternate'

您必须从Feed中获取链接数组,并进行迭代以找到备用链接,然后获取href

You have to get the link array from the feed and iterate to find alternate, then grab the href

类似:

client = gdata.***.service.***Service()

feed = client.Get***VideoFeed('http://gdata.***.com/feeds/api/users/username/uploads')

for link in feed.link:
  if link.rel == 'alternate':
    print link.href

输出:

http://www.***.com/profile_videos?user=用户名

最正确的方法是从用户个人资料供稿中获取备用"链接,因为从技术上讲,上述URL指向上传的视频,而不是主频道页面

The most correct thing would be to grab the 'alternate' link from the user profile feed, as technically the above URL goes to the uploaded videos, not the main channel page

feed = client.Get***UserEntry('http://gdata.***.com/feeds/api/users/username')

for link in feed.link:
  if link.rel == 'alternate':
    print link.href

输出: http://www.***.com/profile?user=username