找到你要的答案

Q:OAuth authentication in twitch.tv with php

Q:在twitch.tv PHP的OAuth认证

I've seen similar Questions like this before but don't understand the correct way of doing it. Or rather the questions were always a little different.

The scenario: I have a site where the user should log in via twitch.tv I have a button which refers him to this url

https://api.twitch.tv/kraken/oauth2/authorize?response_type=code
    &client_id=exampleclientid
    &redirect_uri=http://example.com
    &scope=user_read

I have censored redirect_uri and the client_id but basicly on this site the user needs to login into twitch or if he already is he can authorize that my application gets acess to "scope" here in this case "user_read" which is his email adress.

Now to my problem. When returning to my site my url will look like this

example.com/#access_token=exampleacesstoken&scope=user_read

example acess token is just a combination of numbers and letters which I need to acess private information like his email even his username.

Over this url

https://api.twitch.tv/kraken?oauth_token=exampletoken

I get acess to my needed information, but how do I grab the token from my url via php and delete everything after http://example.com to make it look good again.

The offical API documentation might be helpful and talks about CURL but I don't understand how it works and the PHP manual is very indepth.

https://github.com/justintv/Twitch-API

Sorry if I'm taking the lazy way here, but I think I'm missunderstanding something big because I just have to make a simple grab of the URL

我以前见过类似的问题,但不明白正确的方法。更确切地说,问题总是有点不同。

The scenario: I have a site where the user should log in via twitch.tv I have a button which refers him to this url

https://api.twitch.tv/kraken/oauth2/authorize?response_type=code
    &client_id=exampleclientid
    &redirect_uri=http://example.com
    &scope=user_read

我已审查redirect_uri和client_id但基本上这个网站的用户需要登录到抽搐或如果他已经是他可以授权我的应用程序获取访问“范围”在这里,在这种情况下,“user_read”这是他的电子邮件地址。

现在我的问题。当返回到我的网站我的网址将看起来像这样

example.com/#access_token=exampleacesstoken&scope=user_read

例如访问令牌只是一个数字,我需要访问私人信息如他的电子邮件,甚至他的用户名的字母组合。

在这个URL

https://api.twitch.tv/kraken?oauth_token=exampletoken

我没有我需要的信息,但我怎么抢我的网址通过PHP标记并删除一切http://example.com使它看起来好后再。

官方的API文档,可能会有帮助,谈曲但我不知道它是如何工作的,PHP手册是非常深。

https://github.com/justintv/twitch-api

对不起,如果我以懒散的方式在这里,但我想我missunderstanding大事因为我得做一个简单的URL抓取

answer1: 回答1:

From the Twitch documentation:

https://github.com/justintv/Twitch-API/blob/master/authentication.md#implicit-grant-flow

If the user authorizes your application, they will be redirected to the following URL:

https://[your registered redirect URI]/#access_token=[an access token]&scope=[authorized scopes]

Note that the access token is in the URL fragment, not the query string, so it won't show up in HTTP requests to your server. URL fragments can be accessed from JavaScript with document.location.hash.

从抽搐文档:

https://github.com/justintv/twitch-api/blob/master/authentication.md#implicit-grant-flow

If the user authorizes your application, they will be redirected to the following URL:

https://[your registered redirect URI]/#access_token=[an access token]&scope=[authorized scopes]

Note that the access token is in the URL fragment, not the query string, so it won't show up in HTTP requests to your server. URL fragments can be accessed from JavaScript with document.location.hash.

php  curl  oauth