HyBirdAuth Twitch 订阅者?
HyBirdAuth Twitch Subscriber?
我已经编写了自己的函数来检查用户是否已订阅,但我是使用自己的身份验证方法执行此操作的,如何使用 hybirdauth 来使用我的函数来检查用户的登录是否是订阅者?我知道我可以通过 Hybrid_Provider_Adapter::getAccessToken() 获取访问令牌。我的函数 returns 一个简单的 httpd 200 if 订阅者,任何其他值都不重要。我的主要问题是我可以在哪里插入我的函数,我应该在哪里调用以检查 http 代码。我已将 user_subscribe 添加为有效的附加范围。
public function subcheck($access_token){
$username = $this->authenticated_user($access_token);
$url="https://api.twitch.tv/kraken/users/" . $username . "/subscriptions/".$channel;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/vnd.twitchtv.v3+json', 'Authorization: OAuth '.$access_token));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 0);
// Execute
$result=curl_exec($ch);
$httpdStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Will dump a beauty json :3
//var_dump(json_decode($result, true));
return $httpdStatus;
}
将 public 范围更改为
public $scope = "user_read user_subscriptions";
2.Change 下面的 getUserProfile,这将检查用户是否是子用户,如果用户不是子用户,它将停止脚本并重定向页面。
function getUserProfile()
{
$data = $this->api->api( "user" );
if ( ! isset( $data->name ) ){
throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
}
$access_token = $this->api->access_token;
$username = $data->display_name;
$channel= "Twitch_Channel_Here"
$url="https://api.twitch.tv/kraken/users/" . $username . "/subscriptions/".$channel."";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/vnd.twitchtv.v3+json', 'Authorization: OAuth '.$access_token));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 0);
// Execute
$result=curl_exec($ch);
$httpdStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//Check if Sub?? 200 == Sub?
if ($httpdStatus == "200") {
//Do Nothing
echo 'SUB';
}
else {
//if not a sub then well... ...
header("Location: http://google.com/nonsub.jpg"); /* Redirect browser */
exit();
}
$this->user->profile->identifier = $data->_id;
$this->user->profile->displayName = $data->display_name;
$this->user->profile->photoURL = $data->logo;
$this->user->profile->profileURL = "http://www.twitch.tv/" . $data->name;
$this->user->profile->email = $data->email;
if( ! $this->user->profile->displayName ){
$this->user->profile->displayName = $data->name;
}
我已经编写了自己的函数来检查用户是否已订阅,但我是使用自己的身份验证方法执行此操作的,如何使用 hybirdauth 来使用我的函数来检查用户的登录是否是订阅者?我知道我可以通过 Hybrid_Provider_Adapter::getAccessToken() 获取访问令牌。我的函数 returns 一个简单的 httpd 200 if 订阅者,任何其他值都不重要。我的主要问题是我可以在哪里插入我的函数,我应该在哪里调用以检查 http 代码。我已将 user_subscribe 添加为有效的附加范围。
public function subcheck($access_token){
$username = $this->authenticated_user($access_token);
$url="https://api.twitch.tv/kraken/users/" . $username . "/subscriptions/".$channel;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/vnd.twitchtv.v3+json', 'Authorization: OAuth '.$access_token));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 0);
// Execute
$result=curl_exec($ch);
$httpdStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Will dump a beauty json :3
//var_dump(json_decode($result, true));
return $httpdStatus;
}
将 public 范围更改为
public $scope = "user_read user_subscriptions";
2.Change 下面的 getUserProfile,这将检查用户是否是子用户,如果用户不是子用户,它将停止脚本并重定向页面。
function getUserProfile()
{
$data = $this->api->api( "user" );
if ( ! isset( $data->name ) ){
throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
}
$access_token = $this->api->access_token;
$username = $data->display_name;
$channel= "Twitch_Channel_Here"
$url="https://api.twitch.tv/kraken/users/" . $username . "/subscriptions/".$channel."";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/vnd.twitchtv.v3+json', 'Authorization: OAuth '.$access_token));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 0);
// Execute
$result=curl_exec($ch);
$httpdStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//Check if Sub?? 200 == Sub?
if ($httpdStatus == "200") {
//Do Nothing
echo 'SUB';
}
else {
//if not a sub then well... ...
header("Location: http://google.com/nonsub.jpg"); /* Redirect browser */
exit();
}
$this->user->profile->identifier = $data->_id;
$this->user->profile->displayName = $data->display_name;
$this->user->profile->photoURL = $data->logo;
$this->user->profile->profileURL = "http://www.twitch.tv/" . $data->name;
$this->user->profile->email = $data->email;
if( ! $this->user->profile->displayName ){
$this->user->profile->displayName = $data->name;
}