penguin2048
penguin2048

Reputation: 1343

Can not filter results in vimeo api GET call with fields param

I am using Vimeo API, while making a get call to access a user's video I am doing

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

this is returning a json response

{
    "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
        }
    ]
}

however I am only interested in fields paging, total, and some fields of data array therefore i am using filter as below

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

but the response of above call is

{
"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": [
    []
]

}

Edit: Also the response for the call

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

is

{
"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": [
    []
]

}

I am unable to figure out why the request is not being processed correctly.

Upvotes: 1

Views: 1742

Answers (2)

Inigo
Inigo

Reputation: 8685

This is not a direct answer to this question, but in case anyone else like me ends up finding this page through search results, I have wasted a couple of hours of my life with a similar problem, wondering why the results returned by Vimeo's API were seemingly completely erratic, when dialing up the API using Laravel with this package like so:

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

After a lot of trial and error I discovered that it always seemed to miss the last field listed in the query parameter.

Anyway, the solution was to always send the request with a trailing comma! i.e.

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

Is this an absolutely face-palmingly ridiculous requirement? Why, yes. Yes it is. But there you have it.

Upvotes: 0

Tommy Penner
Tommy Penner

Reputation: 3018

A couple of things: First, the access token should be passed in the auth header of the request, not in the request uri as you mentioned: https://developer.vimeo.com/api/authentication#making-requests

With regards to the fields filter, the filter only applies to the keys nested under data. The paging array is always returned for requests where multiple items are returned.

So your example request should look like this:

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

More info here: https://developer.vimeo.com/api/spec#json-filter

Hope this helps!

Upvotes: 6

Related Questions