justintv / Twitch-API

A home for details about our API
www.twitch.tv
1.72k stars 381 forks source link

Friends API spec release #545

Closed mavrick closed 3 years ago

mavrick commented 8 years ago

Any ETA lads?

Cheers,

Mav

FugiTech commented 8 years ago

It's still in beta...

AlcaDesign commented 8 years ago

Spoilers: not everything is part of Kraken or is beta and is subject to change from Twitch without notice.

Here's what I know from testing:

Scopes

These will return with a 400 - Bad Request JSON reply if you try to send a user to authenticate with them.

{
    "error": "Bad Request",
    "status": 400,
    "message": "Invalid scope requested: user_friends_read"
}

List of friends

URL: https://api.twitch.tv/kraken/users/:user/friends

Method: GET

Authenticated: true

Options:

Schema:

{
    _total: <int>,
    _cursor: <'timestamp in ns'>,
    _links: {
        self: <'url'>,
        next: <'url'>
    },
    friends: [
        {
            created_at: <'friendship date'>
            user: <User object>
        }
    ]
}

Friend relationship

URL: https://api.twitch.tv/kraken/users/:user/friends/:target

Method: GET

Authenticated: true

Schema:

{
    friends: <boolean>,
    status: <'sent_request' | 'friends' | 'no_relation' | etc>,
    user: <User object>
}

404 - No request | " does not have a friend request from ."

Add friend

URL: https://api.twitch.tv/kraken/users/:user/friends/:target

Method: PUT

Authenticated: true

Schema: Success: 204 - No content

Remove friend

URL: https://api.twitch.tv/kraken/users/:user/friends/:target

Method: DELETE

Authenticated: true

Schema: Success: 204 - No content

Get friend requests

URL: https://api.twitch.tv/kraken/users/:user/friends/requests

Method: GET

Authenticated: true

Options:

Schema:

{
    _total: <int>,
    _cursor: <'timestamp in microseconds'>,
    _links: {
        self: <'url'>,
        next: <'url'>
    },
    requests: [
        {
            is_recommended: <boolean>
            is_stranger: <boolean>
            non_stranger_reason: <'mod' | null | etc>
            requested_at: <'timestamp'>,
            user: <User object>
        }
    ]
}

Notification count

URL: https://api.twitch.tv/kraken/users/:user/friends/notifications

Method: GET

Authenticated: true

Schema:

{
    count: <int>
}

Clear notifications (Possibly)

URL: https://api.twitch.tv/kraken/users/:user/friends/notifications

Method: DELETE

Authenticated: true

Schema:

Success: 204 - No content

Get recommended friend list

URL: https://api.twitch.tv/kraken/users/:user/friends/recommended

Method: GET

Authentication: true

Schema:

{
    recommended: [
        {
            user: <User object>
        }
    ]
}

Remove from recommended list

URL: https://api.twitch.tv/kraken/users/:user/friends/recommended/:target

Method: DELETE

Authentication: true

Schema:

204 No Content

Get list of user objects

Also useful to change an ID into a username instead of the hosts API.

URL: https://api.twitch.tv/api/friendships/users?ids=list,of,user,ids

Method: GET

Authenticated: false

Schema:

{
    users: [
        {
            id: <int>,
            display_name: <'Username'>,
            login: <'username'>,
            logo: <'url'>,
            bio: <'user bio'>,
            profile_banner: <'url'>,
            profile_banner_background_color: <'#hexcolor'>
        }
    ]
}

Get friend presence

URL: https://presence.twitch.tv/v1/friends

Method: GET

Authenticated: true

Schema:

{
    data: [
        {
            availability: <'online' | 'offline' | 'idle'>
            index: <int>
            timestamp: <int in seconds>
            user_id: <int>
        }
    ]
}
mavrick commented 8 years ago

Ask and you shall receive @Fugiman ;)

Thanks @AlcaDesign

ghost commented 8 years ago

@AlcaDesign - Great info,

Can you describe the behavior required to get a User:Target friend relationship? Do you just need one at least one valid oauth token? (And make the comparison where the user is compared to the token you have?)

Can you also validate that the list of friends is intended to work without an oauth token? That seems like a bug, unless you're intending to have the list of friends comparison be public.

Example: I would expect this url to give 401 if I don't have a token, rather than a generic channel info https://api.twitch.tv/api/friendships/users?ids=29795919,31723226 (Users are for nl_kripp and cobaltstreak)

AlcaDesign commented 8 years ago

@TournyMasterBotCurse I only looked at the network tab in the developers tools to get this data. I don't work for Twitch in any capacity, so anything I know comes from basic testing using the token that Twitch made and cached to my session/cookies or whatever.

Get the token:

image

And then test the token: https://api.twitch.tv/kraken?oauth_token= token

image

ghost commented 8 years ago

@AlcaDesign My mistake, good info none-the-less!

grimmy commented 7 years ago

fyi this seems to not work at all anymore. In fact, if you do an oauth request with those scopes your oauth attemp fails with invalid scope.