Solved Getting data from an external website

Discussion in 'Plugin Development' started by YoloSanta, Jun 21, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    YoloSanta

    Hey bukkit community I am writing this because I'm in need of some help so I want to develop a plugin where a players (youtubers) subscriber count is displayed on a sign. But I want to get the data from the website here how can I do this so the signs auto update as well how do i get the data from the website
     
  2. Offline

    timtower Administrator Administrator Moderator

    @YoloSanta That url is using an API, use that API instead of the url itself, lots of nasty html stripping otherwise.
    And an async runnable that checks the site every ... seconds and updates the sign sync when the amount changes.
     
  3. I don't think you can get it from a website like that. Try with some php api for returning YAML response, which will make it easier. For API take a look here: https://stackoverflow.com/questions/30723866/youtube-subscriber-count-with-youtube-data-api-v3. After receiving API response in YAML, parse it and only use the part that you need and then just use

    Sign.setLine(index, subcount);

    Sent from my Xperia M4 Aqua using Tapatalk
     
  4. Offline

    YoloSanta

  5. Offline

    timtower Administrator Administrator Moderator

    @YoloSanta I don't know what they are using, open the page with your browsers dev console, check the http requests.
     
  6. Offline

    YoloSanta

  7. Offline

    timtower Administrator Administrator Moderator

    @YoloSanta Nahh, that is the regular stats for the website itself, I mean the other one that runs every ... seconds.
     
  8. Offline

    YoloSanta

  9. Offline

    timtower Administrator Administrator Moderator

    @YoloSanta I am not talking about looking at the code, I am talking about network traffic.
     
  10. @YoloSanta
    Here's what you need to do:

    Create and obtain a Google API key (go to https://console.developers.google.com/projectselector/apis/credentials). Then you need to enable the Youtube Data API on the Dashboard of the API Manager.

    Now, there are two types of get requests you may want to make. The first one is the main one to get the subcount:

    https://www.googleapis.com/youtube/v3/channels?part=statistics&id=<channelId>&fields=items/statistics/subscriberCount&key=<APIkey>

    (replacing <channelId> with the channel ID, and <APIkey> with the previously obtained APIkey)

    This will return you with a json response like this:
    Code:text
    1. {"items":[{"statistics": {"subscriberCount": "10"}}]}
    From that you should have no problems extracting the subcount using some JSON library.

    There is however a problem. If you don't have a channel ID, but only a channel username. This can be solved by using this request (basically the same as the other one, but "forUsername" instead of "id"):

    https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername=<username>&fields=items/statistics/subscriberCount&key=<APIkey>

    (replacing <username> with the channel username, and <APIkey> with the previously obtained APIkey)

    If you have any questions (such as how to make get requests in a proper manner in Java), feel free to ask!
     
    Last edited: Jun 22, 2017
  11. Offline

    YoloSanta

  12. I didn't help at all, but yeah ;) anyday ;)

    Sent from my Xperia M4 Aqua using Tapatalk
     
  13. Offline

    YoloSanta

    @MGlolenstine
     
  14. Well... Did that even help at all?

    Sent from my Xperia M4 Aqua using Tapatalk
     
  15. Offline

    YoloSanta

    Well I tagged you for helping :)
     
  16. What a vague answer ;) jk thanks anyways... And remember that we're here to help!

    Sent from my Xperia M4 Aqua using Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page