无法使用字段参数在vimeo api GET调用中过滤结果

时间:2017-01-20 19:23:01

标签: vimeo vimeo-api

我正在使用Vimeo API,同时拨打电话访问我正在播放的用户视频

https://api.vimeo.com/users/61402929/videos?access_token=token

这是返回一个json响应

{
    "total": 1,
    "page": 1,
    "per_page": 25,
    "paging": {
        "next": null,
        "previous": null,
        "first": "/users/61402929/videos?access_token=365879aad6244864dab70902890fc1a1&page=1",
        "last": "/users/61402929/videos?access_token=365879aad6244864dab70902890fc1a1&page=1"
    },
    "data": [
        {
            "uri": "/videos/200383630",
            "name": "Bhuvan bam _ Bb ki vines _ playing piano _ Saagar jaisi aankhon waali  _ bhuvan bam  live (360p_30fps_H264-96kbit_AAC)",
            "description": "BB Ki Vines",
            "link": "https://vimeo.com/200383630",
            "duration": 59,
            "width": 320,
            "language": null,
            "height": 320,
            "embed": {
                "uri": null,
                "html": "<iframe src=\"https://player.vimeo.com/video/200383630?badge=0&autopause=0&player_id=0\" width=\"320\" height=\"320\" frameborder=\"0\" title=\"Bhuvan bam _ Bb ki vines _ playing piano _ Saagar jaisi aankhon waali  _ bhuvan bam  live (360p_30fps_H264-96kbit_AAC)\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>",
                "buttons": {
                    "like": true,
                    "watchlater": true,
                    "share": true,
                    "embed": true,
                    "hd": false,
                    "fullscreen": true,
                    "scaling": true
                },
                "logos": {
                    "vimeo": true,
                    "custom": {
                        "active": false,
                        "link": null,
                        "sticky": false
                    }
                },
                "title": {
                    "name": "user",
                    "owner": "user",
                    "portrait": "user"
                },
                "playbar": true,
                "volume": true,
                "color": "00adef"
            },
            "created_time": "2017-01-20T17:57:04+00:00",
            "modified_time": "2017-01-20T17:58:41+00:00",
            "release_time": "2017-01-20T17:57:04+00:00",
            "content_rating": [
                "unrated"
            ],
            "license": null,
            "privacy": {
                "view": "anybody",
                "embed": "public",
                "download": true,
                "add": true,
                "comments": "anybody"
            },
            "pictures": {
                "uri": "/videos/200383630/pictures/613872508",
                "active": true,
                "type": "custom",
                "sizes": [
                    {
                        "width": 100,
                        "height": 75,
                        "link": "https://i.vimeocdn.com/video/613872508_100x75.webp?r=pad",
                        "link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F613872508_100x75.webp&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
                    },
                    {
                        "width": 200,
                        "height": 150,
                        "link": "https://i.vimeocdn.com/video/613872508_200x150.webp?r=pad",
                        "link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F613872508_200x150.webp&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
                    },
                    {
                        "width": 295,
                        "height": 166,
                        "link": "https://i.vimeocdn.com/video/613872508_295x166.webp?r=pad",
                        "link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F613872508_295x166.webp&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
                    },
                    {
                        "width": 640,
                        "height": 640,
                        "link": "https://i.vimeocdn.com/video/613872508_640x640.webp?r=pad",
                        "link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F613872508_640x640.webp&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
                    },
                    {
                        "width": 960,
                        "height": 960,
                        "link": "https://i.vimeocdn.com/video/613872508_960x960.webp?r=pad",
                        "link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F613872508_960x960.webp&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
                    }
                ],
                "resource_key": "fdb74e1e2dcaf7c929cfe14240765f45f2d2a302"
            },
            "tags": [],
            "stats": {
                "plays": 0
            },
            "metadata": {
                "connections": {
                    "comments": {
                        "uri": "/videos/200383630/comments",
                        "options": [
                            "GET",
                            "POST"
                        ],
                        "total": 0
                    },
                    "credits": {
                        "uri": "/videos/200383630/credits",
                        "options": [
                            "GET",
                            "POST"
                        ],
                        "total": 1
                    },
                    "likes": {
                        "uri": "/videos/200383630/likes",
                        "options": [
                            "GET"
                        ],
                        "total": 0
                    },
                    "pictures": {
                        "uri": "/videos/200383630/pictures",
                        "options": [
                            "GET",
                            "POST"
                        ],
                        "total": 1
                    },
                    "texttracks": {
                        "uri": "/videos/200383630/texttracks",
                        "options": [
                            "GET",
                            "POST"
                        ],
                        "total": 0
                    },
                    "related": null
                },
                "interactions": {
                    "watchlater": {
                        "added": false,
                        "added_time": null,
                        "uri": "/users/61402929/watchlater/200383630"
                    }
                }
            },
            "user": {
                "uri": "/users/61402929",
                "name": "Rishabh Kumar",
                "link": "https://vimeo.com/user61402929",
                "location": null,
                "bio": null,
                "created_time": "2017-01-11T16:15:43+00:00",
                "account": "basic",
                "pictures": null,
                "websites": [],
                "metadata": {
                    "connections": {
                        "activities": {
                            "uri": "/users/61402929/activities",
                            "options": [
                                "GET"
                            ]
                        },
                        "albums": {
                            "uri": "/users/61402929/albums",
                            "options": [
                                "GET"
                            ],
                            "total": 0
                        },
                        "appearances": {
                            "uri": "/users/61402929/appearances",
                            "options": [
                                "GET"
                            ],
                            "total": 0
                        },
                        "categories": {
                            "uri": "/users/61402929/categories",
                            "options": [
                                "GET"
                            ],
                            "total": 0
                        },
                        "channels": {
                            "uri": "/users/61402929/channels",
                            "options": [
                                "GET"
                            ],
                            "total": 0
                        },
                        "feed": {
                            "uri": "/users/61402929/feed",
                            "options": [
                                "GET"
                            ]
                        },
                        "followers": {
                            "uri": "/users/61402929/followers",
                            "options": [
                                "GET"
                            ],
                            "total": 0
                        },
                        "following": {
                            "uri": "/users/61402929/following",
                            "options": [
                                "GET"
                            ],
                            "total": 0
                        },
                        "groups": {
                            "uri": "/users/61402929/groups",
                            "options": [
                                "GET"
                            ],
                            "total": 0
                        },
                        "likes": {
                            "uri": "/users/61402929/likes",
                            "options": [
                                "GET"
                            ],
                            "total": 0
                        },
                        "moderated_channels": {
                            "uri": "/users/61402929/channels?filter=moderated",
                            "options": [
                                "GET"
                            ],
                            "total": 0
                        },
                        "portfolios": {
                            "uri": "/users/61402929/portfolios",
                            "options": [
                                "GET"
                            ],
                            "total": 0
                        },
                        "videos": {
                            "uri": "/users/61402929/videos",
                            "options": [
                                "GET"
                            ],
                            "total": 1
                        },
                        "watchlater": {
                            "uri": "/users/61402929/watchlater",
                            "options": [
                                "GET"
                            ],
                            "total": 0
                        },
                        "shared": {
                            "uri": "/users/61402929/shared/videos",
                            "options": [
                                "GET"
                            ],
                            "total": 0
                        },
                        "pictures": {
                            "uri": "/users/61402929/pictures",
                            "options": [
                                "GET",
                                "POST"
                            ],
                            "total": 0
                        },
                        "watched_videos": {
                            "uri": "/me/watched/videos",
                            "options": [
                                "GET"
                            ],
                            "total": 0
                        }
                    }
                },
                "preferences": {
                    "videos": {
                        "privacy": "anybody"
                    }
                },
                "content_filter": [
                    "language",
                    "drugs",
                    "violence",
                    "nudity",
                    "safe",
                    "unrated"
                ],
                "resource_key": "6fe192b4cb782d1341fbf3fb3d0ba04a0295236d"
            },
            "app": null,
            "status": "available",
            "resource_key": "cad1f2b7d388491329363a4936f0219fa4dfd18b",
            "embed_presets": null
        }
    ]
}

但是我只对字段分页,总数和数据数组的某些字段感兴趣,因此我使用过滤器如下所示

https://api.vimeo.com/users/61402929/videos?access_token=token&fields=paging,data.name,data.description,data.link,data.pictures.sizes.link

但上述电话的响应是

{
"total": 1,
"page": 1,
"per_page": 25,
"paging": {
    "next": null,
    "previous": null,
    "first": "/users/61402929/videos?access_token=365879********0902890fc1a1&fields=paging%2Cdata.name%2Cdata.description%2Cdata.link%2Cdata.pictures.sizes.link&page=1",
    "last": "/users/61402929/videos?access_token=365879********0902890fc1a1&fields=paging%2Cdata.name%2Cdata.description%2Cdata.link%2Cdata.pictures.sizes.link&page=1"
},
"data": [
    []
]

}

编辑:也是呼叫的响应

https://api.vimeo.com/users/61402929/videos?access_token=token&fields=paging

{
"total": 1,
"page": 1,
"per_page": 25,
"paging": {
    "next": null,
    "previous": null,
    "first": "/users/61402929/videos?access_token=365879*********70902890fc1a1&fields=paging&page=1",
    "last": "/users/61402929/videos?access_token=365879*********70902890fc1a1&fields=paging&page=1"
},
"data": [
    []
]

}

我无法弄清楚为什么请求没有得到正确处理。

2 个答案:

答案 0 :(得分:4)

以下几点:首先,访问令牌应该在请求的auth头中传递,而不是在你提到的请求uri中传递:https://developer.vimeo.com/api/authentication#making-requests

关于字段过滤器,过滤器仅适用于嵌套在data下的密钥。对于返回多个项目的请求,始终返回paging数组。

因此,您的示例请求应如下所示:

https://api.vimeo.com/users/61402929/videos?fields=name,description,link,pictures.sizes.link

此处有更多信息:https://developer.vimeo.com/api/spec#json-filter

希望这有帮助!

答案 1 :(得分:0)

这不是这个问题的直接答案,但是如果像我这样的人最终都通过搜索结果找到此页面,我会浪费我一生中几个小时的类似问题,想知道为什么返回的结果当使用Laravel和this package拨通API时,Vimeo的API似乎完全不稳定,

$response = Vimeo::request('/me/albums/xxxxxxx/videos?fields=name,uri,duration,width,height,link', `['per_page' => 100], 'GET');`

经过反复试验,我发现它似乎总是错过了查询参数中列出的最后一个字段。

无论如何,解决方案是始终以逗号结尾发送请求!即

$response = Vimeo::request('/me/albums/xxxxxxx/videos?fields=name,uri,duration,width,height,link,', `['per_page' => 100], 'GET');`

这是一个绝对令人发指的荒谬要求吗?为什么是。是的。但是你有。