抽搐API,流网址流网、API

2023-09-07 01:23:35 作者:fear .(恐惧)

我已经开始一个小机器人项目和它的最后一项功能是看抽搐流,但我遇到了挫折。我有红色的抽搐 API 后来发现这个帖子。我的想法是这样的:

-get抽搐拖缆的一个特定的游戏列表。

- 当列表的元素被点击打开流和发挥。

阅读这两个来源我做了一个listfragment与arrayadapter和使用后抽射我装从https响应://api.twitch.tv/kraken/streams游戏=(MyGame)。例如:

  https://api.twitch.tv/kraken/streams?game=League%20of%20Legends 

我得到JSON效应初探了25顶幡并显示它们。这里是我在一个问题上运行。我不知道怎么去流视频网址。

据我的第二个链接以获得不同质量的不同流的视频我必须:

1)获得从http令牌://api.twitch.tv/api/channels/(CHANNELNAME)/的access_token

收到的回应是这样的:

  {令牌: \"{\"user_id\":null,\"channel\":\"riotgames\",\"expires\":1408096127,\"chansub\":{\"view_until\":1924905600,\"restricted_bitrates\":[]},\"private\":{\"allowed_to_view\":true},\"privileged\":false}\",SIG:c81dfc25b90d44ea107cdeae5371df28185bd0ddmobile_restricted:假的} 

这种反应有3个值:令牌,SIG和mobile_restricted

2)使用此http://usher.twitch.tv/select/(CHANNELNAME)以.json nauthsig =(SIG)及nauth =(TOKEN)及allow_source =真,我使用填写域JSON令牌响应

http://usher.twitch.tv/select/riotgames.json?nauthsig=c81dfc25b90d44ea107cdeae5371df28185bd0dd&nauth=\"{\"user_id\":null,\"channel\":\"riotgames\",\"expires\":1408096127,\"chansub\":{\"view_until\":1924905600,\"restricted_bitrates\":[]},\"private\":{\"allowed_to_view\":true},\"privileged\":false}\"&allow_source=true c 关于一些主流的电子商务网站的api调用过程,原理 如当当网 天猫 京东等 或者以下c 的一些api的资料

,但我找回反应总是:

  [] 

这在我的理解意味着流不能活?但在同一时间,我可以看到流去。

我的问题是:我如何与不同质量的现场直播网址吗?什么是错的我给他们打电话的方式吗?

作为一个声明:我非常新的,以任何形式的节目,所以我不pretend明白了一切。我可能忽略了一些或明显错过了。此外,它似乎所以我HTTP后添加额外的空间我不能发布超过2链接。

编辑:随着@rcxrdx我得到了我一直在寻找的响应的帮助。他指出的是,我要带code标记正确。这里是recieving所有的视频​​质量字符串响应EN codeD URL的一个例子:

http://usher.twitch.tv/select/reckful.json?segment_$p$pference=2&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22channel%22%3A%22reckful%22%2C%22expires%22%3A1408897471%2C%22chansub%22%3A%7B%22view_until%22%3A1924905600%2C%22restricted_bitrates%22%3A%5B%5D%7D%2C%22private%22%3A%7B%22allowed_to_view%22%3Atrue%7D%2C%22privileged%22%3Afalse%7D&allow_source=true&type=any&nauthsig=b0e19347528f3675612d4c5d1a030bfa8d9ffb13

东西我损失了一些时间,就是当你收到访问令牌,如果你没有在USER_ID记录将返回null。在像博客文章我已经顶部加了一个最例子,没有明确说。所以是的,如果有人想打抽搐视频的层次结构如下:拿到的access_token,形成URL下面的编辑我的例子中,收到的STRING(它可能会说这是JSON,但它不是)的反应,从得到的视频质量响应并使用VideoView具有以下行来打他们:

 字符串myStream =响应;URI URI = Uri.parse(myStream);videoView.setVideoURI(URI);videoView.requestFocus();videoView.start(); 

解决方案

您正在做的是正确的,你是唯一缺少的就是你的令牌必须是URL-CN codeD,由您选择的方法

如果你想确保你正在做正确的编码步骤,你可以看你通过你的浏览器连接到一个流时发送请求(使用Wireshark,或Chrome网络选项卡),并确保你发送同样的道理。

I have started a small android project and its last feature is watching twitch streams but I have run into a setback. I have red the twitch API and later found this post . My idea is the following:

-get the list of twitch streamers for a particular game.

-when an element of the list is clicked open the stream and play.

After reading those two sources I made a listfragment with arrayadapter and using volley I loaded the response from https ://api.twitch.tv/kraken/streams?game=(MyGame) . ex:

https://api.twitch.tv/kraken/streams?game=League%20of%20Legends

I get JSON reponse for the 25 top streamers and display them. Here is where I run in a problem. I don't know how to get the streams video URL.

According to my second link to get the different quiality stream videos I have to:

1) get token from http ://api.twitch.tv/api/channels/(CHANNELNAME)/access_token

The response recieved looks like this:

{ token: "{"user_id":null,"channel":"riotgames","expires":1408096127,"chansub":{"view_until":1924905600,"restricted_bitrates":[]},"private":{"allowed_to_view":true},"privileged":false}",
sig: "c81dfc25b90d44ea107cdeae5371df28185bd0dd",
mobile_restricted: false
}

this response has 3 values: token, sig and mobile_restricted.

2) using this http ://usher.twitch.tv/select/(CHANNELNAME).json?nauthsig=(SIG)&nauth=(TOKEN)&allow_source=true , I fill in the fields using the json token response

http://usher.twitch.tv/select/riotgames.json?nauthsig=c81dfc25b90d44ea107cdeae5371df28185bd0dd&nauth="{"user_id":null,"channel":"riotgames","expires":1408096127,"chansub":{"view_until":1924905600,"restricted_bitrates":[]},"private":{"allowed_to_view":true},"privileged":false}"&allow_source=true

, but the response I get back is always:

[]

Which to my understanding means that the stream is not live? But in the same time I can see the stream going.

My questions are: How do I get the live stream urls with the different qualities? What is wrong with the way I call them?

As a disclaimer: I'm extremely new to any sort of programming so I don't pretend to understand everything. I might have overlooked something or clearly missed it. Also it seems I can't post more than 2 links so I have added an additional space after http.

Edit: With the help of @rcxrdx I got the response I was looking for. What he pointed out was that I have to encode the token correctly. Here is an example of encoded url for recieving the String response with all the video qualities:

http://usher.twitch.tv/select/reckful.json?segment_preference=2&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22channel%22%3A%22reckful%22%2C%22expires%22%3A1408897471%2C%22chansub%22%3A%7B%22view_until%22%3A1924905600%2C%22restricted_bitrates%22%3A%5B%5D%7D%2C%22private%22%3A%7B%22allowed_to_view%22%3Atrue%7D%2C%22privileged%22%3Afalse%7D&allow_source=true&type=any&nauthsig=b0e19347528f3675612d4c5d1a030bfa8d9ffb13

Something I lost some time to is that when you recieve the access token if you are not logged in the user_id will return null. In most examples like the one from the blog post i have added up top, do not explicitly say that. So yeah, if someone wants to play a twitch video the hierarchy is as follows: get access_token, form the url following my example in the edit , recieve the STRING (it might say it's JSON but it isnt) response, get the video qualities from the response and use a VideoView to play them with the following lines:

String myStream=response;
Uri uri = Uri.parse(myStream);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();

解决方案

You are doing it right, the only thing you are missing is that your token has to be URL-encoded, by the method of your choice.

If you want to make sure that you are doing the encoding step correctly, you can watch the request you send when connecting to a stream through your browser (with wireshark, or the Network tab on Chrome), and make sure you are sending the same token.