Blog

  • Integration of Roku with Vimeo to enable Vimeo video hosting.

    Roku application often uses video hosting in order to give an easy management of videos provided with the various features that Vimeo provide to integrate videos with Roku application.

    Vimeo services come with various plans depending upon the features like the amount of data permitted every year, a number of users permitted to use the account etc , required by the user to host his videos.

    Here we will discuss look at the code required to integrate your application with Vimeo account.

    1. After successfully choosing a plan, our step is to create an app that will provide us with the necessary credentials to be used within the code. The link for creating an app in Vimeo is: https://developer.vimeo.com/

    2. Completing the details for the app, the credential that is required is "Access Token".

    3. This token will be required to call the APIs of the Vimeo to get the JSON data of the videos.

    4. The videos will be saved in the form of albums in Vimeo account. Now the API to get the JSON of the albums' data is "https://api.vimeo.com/users/USER_UNIQUE_NUMBER". Following is the implementation of the code.

    sub showChannelSGScreen()
     mainUrl = "https://api.vimeo.com/users/88043989"
     urlOfAllAlbum = mainUrl + "/albums"
        jsonValue = getDataFromUrl(urlOfAllAlbum.trim())
        list = []
        for each albumItem in jsonvalue.data
                albumName = albumItem.name
                eachVideoUrl = mainUrl + albumItem.metadata.connections.videos.uri
                jsonOfEachVideo = getDataFromUrl(eachVideoUrl.trim())
                videosItem = []
                for each videoData in jsonOfEachVideo.data
                    item = {}
                    item.EpisodeNumber = Right(videoData.uri, 9)
                    item.title = videoData.name
                    item.description = videoData.description
                    item.SDPosterUrl = videoData.pictures.sizes[0].link
                    item.HDPosterUrl = videoData.pictures.sizes[3].link
                    ' here a medium size picture taken , we can choose from 7 different sizes
                    if videoData.duration <> invalid
                        item.Length = videoData.duration
                    else
                        item.Length = 120
                    end if
                    item.hdBackgroundImageUrl = videoData.pictures.sizes.peek().link
                    if item <> invalid then
                        videosItem.push(item)
                    else
                        ? "error in pushin item in videosItem"
                    end if
                end for
                list.push({ Title: albumName
                ContentList: videosItem })
        end for 
    end sub
    
    function getDataFromUrl(url as String) as Object
        request = CreateObject("roUrlTransfer")
        port = CreateObject("roMessagePort")
        request.SetMessagePort(port)
        request.SetUrl(url)
        request.addHeader("Authorization", "bearer f11832710cff860ae2dfwfw32dssn9223dss")
        request.setCertificatesFile("common:/certs/ca-bundle.crt")
        request.initClientCertificates()
        request.enableEncodings(true)
        request.RetainBodyOnError(true)
    
        if (request.AsyncGetToString())
            while (true)
                msg = Wait(0, port)
                if (Type(msg) = "roUrlEvent")
                    code = msg.GetResponseCode()
                    if (code = 200)
                        ' playlist = CreateObject("roArray", 10, true)
                        jsonValue = ParseJson(msg.GetString())
                        return jsonValue
                    else
                        ? "code is other than 200"
                    end if
                else if (event = invalid)
                    ? "REQUEST CANCELLED"
                    request.AsyncCancel()
                end if
            end while
        end if
        ? "RETURNING INVALID"
        return invalid
    end function 
    

    5. Then this data can be inserted into a content node in order to show them into any grid screen. 6. For example, a grid screen could be of a type where we can show consecutive images with various details like description, poster etc as retrieved above. In this way, we can integrate videos on the Vimeo account.

    Hope this will help !!

Tags: roku