首页 文章

从视频URL获取Vine PostID

提问于
浏览
0

我正在使用Vine API包装"VineSharp" nuget包来尝试获取有关Vine视频的一些细节 . 我有视频网址 . 即:“https://vine.co/v/eYgeYlYAOQv”然而,为了得到葡萄藤的数据,显然VineSharp(以及其他Vine API包装纸)要求插入葡萄藤标识 - 我没有 .

我已经搜索了很多谷歌,如果我有视频网址或视频ID,我怎么能得到帖子ID - 但找不到任何东西 .

如果Vine API支持帖子查询以使用帖子的id获取特定帖子的详细信息,那么只能从Json中检索帖子ID本身,如时间轴或 Channels 请求等其他API调用,这是不合逻辑的 .

我错过了什么?

1 回答

  • 1

    一种hacky方法是使用WebClient class下载 https://vine.co/v/eYgeYlYAOQv 的内容并使用正则表达式解析结果 .

    帖子ID在返回的网页中多次出现 . 您可以使用以下正则表达式之一(或两者都可以):

    vine://post/(\d+)[^\d]
    
    "postIdStr":\s*"(\d+)"
    

    第一个匹配组将包含帖子ID .

    这是一个尝试两种模式的工作示例:https://regex101.com/r/aV9fD8/4

    这是一个下载网站,尝试两种模式并打印第一个匹配的帖子ID的工作示例:https://dotnetfiddle.net/klWnxw

    using (var client = new WebClient())
    {       
        var content = client.DownloadString("https://vine.co/v/eYgeYlYAOQv");
    
        var postIdMatch = Regex.Match(
            content, 
            @"vine://post/(\d+)[^\d]|""postIdStr"":\s*""(\d+)""");
    
        if (postIdMatch.Success)
            Console.WriteLine(
                postIdMatch.Groups[1].Value != string.Empty 
                    ? postIdMatch.Groups[1].Value 
                    : postIdMatch.Groups[2].Value);
        else
            Console.WriteLine("No post ID found.");
    }
    

    输出:

    1270971006727159808

相关问题