【问题标题】:How to set Twitch TV channel title如何设置 Twitch 电视频道标题
【发布时间】:2015-10-08 21:28:53
【问题描述】:

我正在努力让我的自定义聊天机器人更新我的主要频道的标题(状态)。我正在关注this 的帖子,我正在尝试从REDIRECT_URI 获取access_token

包含重定向的 URI 是:

https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&scope=channel_editor

我已经手动测试了我的 CLIENT_IDREDIRECT_URI 设置为 http://localhost 并且我从上面的 URI 中得到了这个响应(这是我想要的):

http://localhost/#access_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&scope=channel_editor

我正在尝试从此 URI 获取 access_token,但我似乎无法从下面的代码中获取它。我的回答是:

https://api.twitch.tv/kraken/oauth2/authenticate?action=authorize&client_id=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&redirect_uri=http%3A%2F%2Flocalhost&response_type=token&scope=channel_editor

代码:

string clientID = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
string redirectURL = "http://localhost";

string url = string.Format("https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id={0}&redirect_uri={1}&scope=channel_editor",
                 clientID, redirectURL);

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = false;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string redirUrl = response.Headers["Location"];
response.Close();

// Show the redirected url
Console.WriteLine("You're being redirected to: " + redirUrl);

这是一个控制台应用程序

【问题讨论】:

    标签: c# api curl restsharp twitch


    【解决方案1】:

    这与 c# 没有直接关系,但实现它应该很容易https://discuss.dev.twitch.tv/t/how-to-set-title/390/2

    【讨论】:

    • 我实际上在问题中有指向该帖子的链接。我最近找到了实现这一点的官方文档。我意识到我需要使用身份验证代码而不是隐式授权来实现这一点。链接在这里:github.com/justintv/Twitch-API/blob/master/…
    • 哦,对不起,我没有看到那个链接
    • 一切都好。直到现在我才意识到这个链接有多晦涩。
    • 我发布了我对这个问题的回答。感谢您引导我找到我的发现
    【解决方案2】:

    This twitch dev post 帮助我,直到我进入“提出请求”步骤。我的问题是我需要使 C# 等效于这个 cURL 命令来更改频道的标题:

    curl -H 'Accept: application/vnd.twitchtv.v2+json' 
         -H 'Authorization: OAuth <access_token>' 
         -d "channel[status]=New+Status!&channel[game]=New+Game!" 
         -X PUT https://api.twitch.tv/kraken/channels/CHANNEL
    

    解决方案

    我决定通过 ctrl + cctrl + v kbd> 来自下面给出的 URI 的令牌并将其存储到我的数据库中:

    http://localhost/#access_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&scope=channel_editor
    

    然后,我使用Postman 生成我的RestSharp 代码,其中包含 JSON 中的正文请求:

    string accessToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    
    var client = new RestClient("https://api.twitch.tv/kraken/channels/CHANNEL_NAME");
    var request = new RestRequest(Method.PUT);
    request.AddHeader("cache-control", "no-cache");
    request.AddHeader("content-type", "application/json");
    request.AddHeader("authorization", "OAuth " + accessToken);
    request.AddHeader("accept", "application/vnd.twitchtv.v3+json");
    request.AddParameter("application/json", "{\"channel\":{\"status\":\"Hello World\"}}", 
        ParameterType.RequestBody);
    
    IRestResponse response = client.Execute(request);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-31
      • 1970-01-01
      • 1970-01-01
      • 2020-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多