Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authorization problem when retrieving user data #155

Open
Be-Mann opened this issue Jul 21, 2023 · 2 comments
Open

Authorization problem when retrieving user data #155

Be-Mann opened this issue Jul 21, 2023 · 2 comments

Comments

@Be-Mann
Copy link

Be-Mann commented Jul 21, 2023

Hi, I tried to retrieve the user data, but unfortunately I always get a fatal error

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: GET https://api.twitch.tv/helix/users resulted in a 401 Unauthorized response: {"error": "Unauthorized", "status":401, "message": "Client ID and OAuth token do not match"}

Here is the code snippet I use:

`

    $code = (isset($_GET['code']) and $_GET['code']) ? $_GET['code'] : null;
    try {
        $token = $oauth->getUserAccessToken($code, $login_query);
        // It is a good practice to check the status code when they've responded, this really is optional though
        if ($token->getStatusCode() == 200) {
            // Below is the returned token data
            $data = json_decode($token->getBody()->getContents());

            // Your bearer token
            $twitch_access_token = $data->access_token ?? null;


        } else {
        //TODO: Handle Error
        }
    } catch (Exception $e) {
        //TODO: Handle Error
        var_dump($e);
    }

    try {
        // Make the API call. A ResponseInterface object is returned.
        $response = $twitchlogin->getUsersApi()->getUserByAccessToken($twitch_access_token);

        // Get and decode the actual content sent by Twitch.
        $responseContent = json_decode($response->getBody()->getContents());

        // Return the first (or only) user.
        return $responseContent->data[0];
    } catch (GuzzleException $e) {
        //TODO: Handle Error
        var_dump($e);
    }`
@Be-Mann Be-Mann changed the title helix/users Unauthorized Authorization Prolem when retrieving user data Jul 21, 2023
@Be-Mann Be-Mann changed the title Authorization Prolem when retrieving user data Authorization problem when retrieving user data Jul 21, 2023
@Be-Mann
Copy link
Author

Be-Mann commented Jul 22, 2023

In "RequestGenerator" $headers['client-id'] must be added to the header, then it works, but I didn't manage to retrieve the $clientId from OauthApi, I'm not so into object oriented programming.

@Be-Mann
Copy link
Author

Be-Mann commented Mar 11, 2024

Wanted to ask if there will be a fix? @nicklaw5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant