Code:java import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.net.MalformedURLException;import java.net.URL; import org.json.simple.JSONObject;import org.json.simple.parser.JSONParser;import org.json.simple.parser.ParseException; public class YoutubeChannel { private JSONObject json;private String channelName;private URL channelURL;private String channelInformation; public YoutubeChannel(String name) {channelName = name;try {channelURL = new URL("[URL]http://gdata.youtube.com/feeds/api/users/[/URL]" + name +"?v=2&alt=json");} catch (MalformedURLException e) {}update();} public boolean update() {try {BufferedReader br = new BufferedReader(new InputStreamReader(channelURL.openStream()));channelInformation = br.readLine();br.close();try {json = (JSONObject) new JSONParser().parse(channelInformation);json = (JSONObject) json.get("entry");JSONObject json2 = (JSONObject) json.get("yt$firstName");channelName = (String) json2.get("$t");return true;} catch (ParseException e) {}} catch (IOException e) {}return false;} public String getName() {return channelName;} public String getDisplayName() {JSONObject json2 = (JSONObject) json.get("yt$username");return (String) json2.get("display");} public String getLocation() {JSONObject json2 = (JSONObject) json.get("yt$location");return (String) json2.get("$t");} public String getSummary() {JSONObject json2 = (JSONObject) json.get("summary");return (String) json2.get("$t");} public String getGooglePlusId() {JSONObject json2 = (JSONObject) json.get("yt$googlePlusUserId");return (String) json2.get("$t");} public int getSubscriberCount() {JSONObject json2 = (JSONObject) json.get("yt$statistics");String s = (String) json2.get("subscriberCount");int number = Integer.parseInt(s);return number;} public int getTotalViews() {JSONObject json2 = (JSONObject) json.get("yt$statistics");String s = (String) json2.get("totalUploadViews");int number = Integer.parseInt(s);return number;} } Hope you find this useful. If you make something out of this please comment it, I would love to see what you could make with it. I made one for twitch too. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Retherz_ this don't work for me. Getting NPE: Caused by: java.lang.NullPointerException at eu.zonegames.api.YoutubeChannel.update(YoutubeChannel.java:38) ~[?:?] at eu.zonegames.api.YoutubeChannel.<init>(YoutubeChannel.java:26) ~[?:?] EDIT: Row 38 is this: channelName = (String) json2.get("$t");
How does your plugin work in terms of verifying the YouTube account? I just finished making a plugin that does it and was wondering how yours does this?
Like this: Code:java try {YoutubeChannel channel = new YoutubeChannel(args[1]);if(channel.getDisplayName().contains("[" + sender.getName() + ":" + getConfig().getString("ServerName") + "]")) {if(channel.getSubscriberCount() >= getConfig().getInt("MinimumSubscribers")) { for(String s : getConfig().getStringList("Commands")) {String command = s.replaceAll("{playername}", sender.getName());command = command.replaceAll("{channelurl}", "[url]http://youtube.com/[/url]" + args[1]);getServer().dispatchCommand(getServer().getConsoleSender(), command);}getConfig().getStringList("YouTubers").add(uuid);getConfig().getStringList("YoutubeChannels").add(args[1].toLowerCase());sender.sendMessage(ChatColor.GOLD + "[" + ChatColor.DARK_GRAY + "You" + ChatColor.WHITE + "Tube" + ChatColor.GREEN + "Reward"+ ChatColor.GOLD + "] " + ChatColor.AQUA+ "You have sucessfully linked your channel with your account!");return true;} else {//Not enough subscriberssender.sendMessage(ChatColor.GOLD + "[" + ChatColor.DARK_GRAY + "You" + ChatColor.WHITE + "Tube" + ChatColor.GREEN + "Reward"+ ChatColor.GOLD + "] " + ChatColor.AQUA+ "You have too few subscribers! You need " + ChatColor.GOLD + (getConfig().getInt("MinimumSubscribers") - channel.getSubscriberCount()) + ChatColor.AQUA + " more subscribers.");return true;}} elsesender.sendMessage(ChatColor.AQUA+ "- Change your account name to: " + ChatColor.GRAY + "[" + sender.getName() + ":" + getConfig().getString("ServerName") + "]");} catch(Exception e) {sender.sendMessage(ChatColor.GOLD + "[" + ChatColor.DARK_GRAY + "You" + ChatColor.WHITE + "Tube" + ChatColor.GREEN + "Reward"+ ChatColor.GOLD + "] " + ChatColor.AQUA+ "An error has occured or invalid information was entered.");return true;}
I'm still waiting for mine to get approved :3 Also does yours actually check if they own the account in any way?