GET user json inside Unreal Engine С++

TSharedRef Request = Http->CreateRequest();
Request->OnProcessRequestComplete().BindUObject(this, &AMyActor::OnResponseReceivedUserLogo);
Request->SetURL(url); // TEXT(“https://api.twitch.tv/” + userName + “/user”)
Request->SetVerb(“GET”);
Request->SetHeader(What here???, TEXT(“application/json”));
Request->ProcessRequest();

What i must write in header? Another code is ok?

There are multiple headers you’ll need to send on a request, and they vary by endpoint. For the user endpoint, you’ll need to send the Accept header to specify Kraken v5, the Authorization header to provide the user’s OAuth token, and the Client-ID header to send your Client-ID. You can see examples of each of these in the user endpoint documentation. They are the lines that have -H in them.

1 Like

Something like this?
Request->SetHeader(“Accept”, "application/vnd.twitchtv.v5+json);
Request->SetHeader(“Client-ID”, “MyToken”);
Request->SetHeader(“Authorization”, “TargetAuterizationToken”);
TargetAuterizationToken is private, isnt’ it?

In global i want to get User Object (user’s logo in fact). Is it posible, if i know only nickname (from chat)?

Thanks for helping!

OAuth tokens are all private and per-user. Treat them like passwords as they allow you to take action on a user’s behalf. To get the user object, you don’t need an OAuth token though. You can simply call the Get User by ID endpoint to get the user object. If you have the user’s name, you can get the ID using the API call outlined in the documentation.

1 Like

Thank you!

Can i use my token as Client-ID? I’m trying but get 400 error like: “Requests without a client ID fail with an HTTP 400 error.” I make a mistake in this moment, or it’s correct?

Already solved.

If you are passing a valid token you don’t need to also send a client ID since it can be inferred from the token. However I personally send one anyway.

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