Android + API Token + IRC User List?

So I just started dev’ing on Android, and I wanted to add several features to my Android app:

  1. Show all the users in chat (excluding the streamer)
  2. Allow the user to update the title / game

Things I already know / have:

  1. How the API token system works
  2. How to connect to IRC in Twitch using TMI
  3. Title / game edit fields + update button
  4. How to use the authorization token + the title / game strings to update the title / game

I would have the app poll twitch’s API every 5 seconds.

My issues (of which I need help with):

  1. I will ask about how to connect to the IRC on another site, so are all the user’s in the IRC channels invisible? (+i) I don’t want to have the client join a channel to see the user list, if possible.
  2. I am using Java + XML in my application, how do I get the auth token on android?
    I could open the default browser to the API link for my application (to get the token) but then how do I get the API’s token into a string?
    (I would ask this on Stack Overflow, but I cannot sadly)
    (Also I already asked an admin if this app could have the “special” permission grant-flow, and he said write a websocket)
    I have researched websockets quite a bit now, and still have no clue how that would help? Unless I could get the redirect URL to go to it? Even then how do I get the API token from the URL using Java… I really don’t want to use JavaScript.

Finally I wanted to ask, should I have the application set to poll every 5 seconds? I don’t want to spam the API, and I found that the more you request info from the API, the slower it updates… Any words on this? Is there a way I could do this better?

Thanks in advance!
Sean.

  1. I am using Java + XML in my application, how do I get the auth token on android? I could open the default browser to the API link for
    my application (to get the token) but then how do I get the API’s
    token into a string? (I would ask this on Stack Overflow, but I cannot
    sadly) (Also I already asked an admin if this app could have the
    “special” permission grant-flow, and he said write a websocket) I have
    researched websockets quite a bit now, and still have no clue how that
    would help? Unless I could get the redirect URL to go to it? Even then
    how do I get the API token from the URL using Java… I really don’t
    want to use JavaScript.

I use Delphi, but this may help how to get token without using JS, all you need is password and login to the Twitch.

Thanks, but… I have already tried this in the past, and the server will throw a 400-ish code everytime you try it, unless you contact an admin, and have him give you the okay to use this type of grant-flow in an application.

I think it was done that way to stop malicious application’s from getting people’s username / password.

EDIT:
Il give it a shot, you are doing it slightly differently than I did in the past.

good luck with grant-flow , i also tried to get this, but no answer :stuck_out_tongue: So made diffrent stuff to makes users life easier.

im also using to set game and description. Is little slow, but it works fine and is easy for users :slight_smile:

To use grant flow in a desktop application, you can start a webserver on the user’s machine on a high numbered port, then set your redirect url to 127.0.0.1:. That way you can open the oauth flow in the user’s browser, have it redirect to the webserver being run by your app, which can then save the oauth token and close the browser. Unfortunately I do not know of any sample code for this.

1 Like

I use the Implicit Grant Flow in my application. It’s a desktop application and I’m not really familiar with Android coding, so I’m not sure if it will work the same for you.

  1. Send user to open the URL to authorize with Twitch
  2. Set the redirect to 127.0.0.1:<someport>
  3. With a webserver running in your program, deliver a page with a little JavaScript that will grab the token from the #access_token= URL fragment and redirect to a page that has the token in the URL, so the webserver can see it
  4. Get the token from the URL and deliever another page telling the user you are done (or close the browser if you can easily do that on Android)

Maybe you can also get the token immediately somehow, not quite sure how that works on Android, if you can access the addressbar of the browser when your app started it or something.

If you think you could use code written for a Java desktop application, you can download my code here: https://sourceforge.net/projects/getchatty/files/?source=navbar (Check out Webserver.java and the HTML files in /src/chatty/util)