Embed private Vimeo videos in both a web app AND mobile apps — Ionic/Angular

前端 未结 1 1618
南笙
南笙 2021-02-10 01:38

I have a situation where we are both the owners of a Vimeo pro account containing private videos and the developers of an Ionic/Angular application where we embed those videos.<

相关标签:
1条回答
  • 2021-02-10 02:16

    If you just need to embed the videos in a website, you can keep your videos private on Vimeo AND authorize the videos to be embeded in your site by going to https://vimeo.com/settings/videos/upload_defaults, setting the "Where can your videos be embedded?" option to "Only sites I choose", and then adding the domain of your website using the "Add domain" button.

    This will work for websites, but doesn't work to well for apps (unless your app contains a webview or iframe that points to a page on your website instead of the video actually being embeded in your app). A possible solution in this case would be to use the distribution options in your video's settings (https://vimeo.com/manage/{assetID}/distribution). Near the bottom of the page you'll find a "Video file links" section which will provide you with links for either downloading or streaming your video. These are links to the actual video, and so cannot be controlled in the same way as the usual embed code links, so be careful where and when you use them.

    If you really need to make an API call, I'm having some problems of my own and so can only offer limited assistance. Currently I am able to make an API call (PHP example included below) to Vimeo's API endpoint, provide my access token, and get a result that includes the requested information, but ONLY if the access token that I use is one I generated awhile ago for an old app. Any of the new access tokens that I generate (either in the new or old apps in my account, doesn't seem to matter) will not work. The same goes for any of the access tokens retrieved using the OAuth 2.0 process outlined on Vimeo's site. Extremely frustrating...

    It seems like all of the OAuth 2.0 API workflows Vimeo suggests are for granting developer access to the end users's videos rather than granting the end user access to the developer's videos.

        $albumsVideosURL = "https://api.vimeo.com/users/$userID/albums/$albumID/videos?&per_page=2";
    
        $headers = array( 
            "Content-type: application/json", 
            "Accept: application/vnd.vimeo.*+json;version=3.4", 
            "Authorization: Bearer " . $access_token,
            "scope: public private video_files",
        );
    
        $ch = curl_init($albumsVideosURL);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);  
        $data = curl_exec($ch);
        curl_close($ch);
    

    EDIT:

    I finally got it working! And without having to install Vimeo's PHP SDK library!

    It came down to the Authentication type! I kept trying Basic and Oauth, but it needs to be set to Bearer! I've edited the PHP code in the example above to reflect my current understanding and I'll include a JavaScript example below. It looks like you don't need to include the content type, accept, or scope in the headers either. All you really need is the authentication, and the authentication has to be set to Bearer.

    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            var output = this.responseText;
            console.log(output);
        }
    };
    xmlhttp.open("GET", endpoint, true);
    xmlhttp.setRequestHeader("Authorization", "Bearer " + access_token);
    xmlhttp.send();
    

    I really wish the Vimeo Support tech had just opened with that instead of repeatedly telling me to set the set the header without telling me what type to use... Oh well, got there in the end.

    0 讨论(0)
提交回复
热议问题