Created
January 26, 2016 07:30
-
-
Save irfanfadilah/7f5c631a39521ef8bc9e to your computer and use it in GitHub Desktop.
DailyMotion API Snippet for Live Event (Broadcast and Stream)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client_id = "xxxxxxxxxxxxxxxxxxxx" | |
client_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
redirect_uri = "http://localhost:3000/callback/dailymotion" | |
# Ask user permission | |
get = "https://www.dailymotion.com/oauth/authorize?response_type=code&client_id=#{client_id}&redirect_uri=#{redirect_uri}&scope=manage_videos" | |
# Get access_token & refresh_token | |
params = { | |
grant_type: "authorization_code", | |
client_id: client_id, | |
client_secret: client_secret, | |
redirect_uri: redirect_uri, | |
code: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
} | |
res = RestClient.post("https://api.dailymotion.com/oauth/token", params) | |
# Get access_token using refresh_token | |
refresh_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
params = { | |
grant_type: "refresh_token", | |
client_id: client_id, | |
client_secret: client_secret, | |
refresh_token: refresh_token | |
} | |
res = RestClient.post("https://api.dailymotion.com/oauth/token", params) | |
# Create live stream | |
access_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
params = { mode: "live", published: true, channel: "irfanfadilah", title: "Some Awesome Title Here" } | |
headers = { "Authorization" => "Bearer #{access_token}" } | |
res = RestClient.post("https://api.dailymotion.com/videos", params, headers) | |
# Get host and stream name | |
video_id = "xxxxxxx" | |
headers = { "Authorization" => "Bearer #{access_token}" } | |
res = RestClient.post("https://api.dailymotion.com/video/#{video_id}", { fields: "live_publish_url" }, headers) | |
wowza_stream_name = "last" | |
dailymotion_host = "publish.dailymotion.com" | |
dailymotion_application = "publish-dm" | |
dailymotion_stream_name = JSON.parse(res)["live_publish_url"].split("/").last | |
wowza_host = "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/awesome" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment