Request all things about a specified channel

I want to get all info about a single channel. Well I only need the title of the stream.
I will try to us in flutter but Im stuck making the request url.
Want to see what it returns in the browser. I got my client_id and the channel name(not id).
Please help me wit the url creation.
A bit confused because there are many answers but it looks there are for the old api.
https://api.twitch.tv/kraken/streams?game=poker&client_id=MY_ID
I have made a successful request like this. But it doesn`t return what I need.

Well what are you trying to do.

This request gets all streams that are streaming the game “Poker” and the response payload contains the title of the stream.

You just need to fetch the URL as you already have, JSON parse the response, iterate over the streams and read out the titles.

1 Like

I want to build an mobile app for a streamer that checks his title for a specific keyword. That`s why I want to avoid iterating over multiple streams. Just want to focus on one and look if the title contain the keyword and in turn notify the user.
Can I isolate just one streamer with a query or do I need to write code that first singles out the user from the whole “Poker” stack and than scrape his title for the keyword?
I wanted to single out the streamer because sometimes he chooses to pick a joke/game type but still plays poker. In that case the query wont show him in the “poker” category.

As documented

Call streams with a user_id or user_login

I`m following a video tutorial using

package:http/http.dart

package and it requires an URL witch I want to parse.
Im new at this so the question might be obvious.
I tried reading the documentation before.
I`m trying:

https://api.twitch.tv/kraken/streams/?user_login=easywithaces&client_id=MY_ID
Want to get this data from user “easywithaces”.
Parse the title(status) and look for keywords in it.
I just can`t get the request url right.

v5/kraken is deprecated so I linked to the helix/new API.

It’s URL is

https://api.twitch.tv/helix/streams?user_login=easywithaces

ClienID should be passed as a header as documented

Yeah. I already tried it but still confused about the Client_id.
Puting it at the end of the url - &client_id=MY_ID returns: * “message”: “Must provide a valid Client-ID or OAuth token”
I stumbled on to this: https://i.imgur.com/6dnmZj6.png
“You need to send it as a header, not a query string parameter.”
Meaning?
The furthest I got is a response from:
http.Response response = await http
get(‘https://api.twitch.tv/kraken/streams/?game=Poker&$clientId’);
But the response was 50+ streams.
That why I want the client_id in the url. Not sure where to declare it separately
Thanks for the patience guys.

Sending it as a query string argument (aka in the url) is deprecated like Kraken/v5 and is generally speaking bad practice (for when you move on to oAuth’ed requests)

Add authorization headers

The http package provides a convenient way to add headers to your requests. Alternatively, use the HttpHeadersclass from the dart:io library.

content_copy

Future<http.Response> fetchPost() {
  return http.get(
    'https://jsonplaceholder.typicode.com/posts/1',
    // Send authorization headers to the backend.
    headers: {HttpHeaders.authorizationHeader: "Basic your_api_token_here"},
  );
}
class UserAgentClient extends http.BaseClient {
  final String userAgent;
  final http.Client _inner;

  UserAgentClient(this.userAgent, this._inner);

  Future<StreamedResponse> send(BaseRequest request) {
    request.headers['user-agent'] = userAgent;
    return _inner.send(request);
  }
}
import 'dart:html';
import 'dart:convert';
void main() {
  var data = { 'title' : 'My first post' };
  HttpRequest.request(
    'https://jsonplaceholder.typicode.com/posts',
    method: 'POST',
    sendData: json.encode(data),
    requestHeaders: {
      'Content-Type': 'application/json; charset=UTF-8'
    }
  )
  .then((resp) {
    print(resp.responseUrl);
    print(resp.responseText);           
  });
}

Seem to be relevant (google hits 1 and 2 and 3 for how to send a header)

No idea if any of these work, this is not a Dart Support forum.

1 Like

Thank you! Made things a lot clearer. Will try and report later.
Thanks again

So I did this:

void fetchPost() async {
http.Response response = await http.get(
‘https://api.twitch.tv/helix/streams?user_login=easywithaces’,

headers: {
HttpHeaders.authorizationHeader:
“Client-ID: the_clientId_from_dashboard”},
);
print(response.statusCode);
// 401
print(response.body);
// { “error”:“Unauthorized”,“status”:401,“message”:“Must provide a valid Client-ID or OAuth token”}

}

but still getting 401. It seems like wrong syntax on the ID. Read the documentation and it said

headers: use ‘Client-ID: Key’

Have gone trough the documentatin multiple times and the example request returns some data

But when I change the url in the http.get() and change the headers to HttpHeaders.authorizationHeader to my id i get the error. What is the syntax here?
“HttpHeaders.authorizationHeader: “MY_ID””
or
'HttpHeaders.authorizationHeader: “Basic MY_ID”"
The most confusing thing is the Client-ID and OAuth token. Do I need to generate the secret key or twitch only requires ID
Sorry to bombard you with noob questions.

https://api.twitch.tv/helix/streams?user_login=easywithaces

This API endpoint does not require authentication.

As the response says you must provide a valid ClientID header.

As per the docs

The example request is

curl -H 'Client-ID: uo6dggojyb8d6soh92zknwmi5ej1q2' \
-X GET 'https://api.twitch.tv/helix/streams?first=20'

This is not a Flutter support forum.

Client ID should be sent as a Client-ID: whatever header

ClientID and Secret allows you to generate an App Access Token, which can be sent as an Authorization header Authorization: Bearer GeneratedToken But you still should send the ClientID header with it.

ClientID and Secret can be uses to generate a User Access Token, and that token can be sent as a Authorization header.

Currently you can’t get non authenticated requests working.

From my reading it should be (I can’t test this I don’t know flutter or have a suitable environment setup)

import 'dart:html';
import 'dart:convert';
void main() {
  HttpRequest.request(
    'https://api.twitch.tv/helix/streams?user_login=easywithaces',
    method: 'GET',
    requestHeaders: {
      'Client-ID': 'YourClientID'
    }
  )
  .then((resp) {
    print(resp.responseUrl);
    print(resp.responseText);           
  });
}

As I covered here

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.