public static void GetFollowerIDs(string name, string AccessToken, twitterButton caller) { Dictionary<string, string> headers = new Dictionary<string, string>(); headers["Authorization"] = "Bearer " + AccessToken; WWW web = new WWW("https://api.twitter.com/1.1/followers/ids.json?screen_name=" + name, null, headers); while (!web.isDone) { Debug.Log("Retrieving follower IDs..."); } Debug.Log(web.text); List<string> dummy = extractData(web.text, "[", "]"); List<string> IDs = extractData(dummy[0], ","); caller.IDs = IDs; }
public static void GetProfile(string userID, bool isID, string AccessToken, twitterButton caller, bool zombie) { Dictionary<string, string> headers = new Dictionary<string, string>(); headers["Authorization"] = "Bearer " + AccessToken; string url = "https://api.twitter.com/1.1/users/show.json"; if (isID) { url += "?user_id="; } else { url += "?screen_name="; } WWW web = new WWW(url + userID, null, headers); while (!web.isDone) { Debug.Log("Grabbing profile info..."); } Debug.Log(userID); Debug.Log("web: " + "\n" + web.text); Debug.Log("Extracting profile data..."); List<string> avatarURL = extractData(web.text, ",\"profile_image_url\":\"", "\",\"profile_image_url_https\":"); avatarURL[0] = avatarURL[0].Remove(avatarURL[0].IndexOf("_normal"), 7); List<string> text = extractData(web.text, ",\"text\":\"", ",\"source\":"); int a = web.text.IndexOf("\"status\"", 0); int b = web.text.IndexOf("\"contributors_enabled\"", 0); int length = b - a; string newText = web.text; if (a != -1 && b != -1) { newText = web.text.Remove(a, length); Debug.Log(newText); } int c = web.text.IndexOf(",\"profile_location\":", 0); int d = web.text.IndexOf(",\"description\":", 0); int lengthROUNDTWO = d - c; if (c != -1 && d != -1) { Debug.Log(c + " " + d); newText = newText.Remove(c + 22, lengthROUNDTWO - 22); } List<string> anID = extractData(newText, "{\"id\":", ",\"id_str\":"); List<string> displayName = extractData(newText, ",\"name\":\"", "\",\"screen_name\":"); List<string> username = extractData(newText, ",\"screen_name\":\"", "\",\"location\":"); List<string> location = extractData(newText, ",\"location\":\"", "\",\"profile_location\":"); List<string> bio = extractData(newText, ",\"description\":\"", "\",\"url\":"); List<string> website = extractData(newText, ",\"display_url\":\"", "\",\"indices\":"); List<string> joinDate = extractData(newText, ",\"created_at\":\"", "\",\"favourites_count\":"); List<string> verified = extractData(newText, ",\"verified\":", ",\"statuses_count\":"); List<string> totalTweets = extractData(newText, ",\"statuses_count\":", ",\"lang\":"); List<string> followers = extractData(newText, ",\"followers_count\":", ",\"friends_count\":"); TwitterUser user = new TwitterUser(); user.ID = anID[0]; user.displayName = displayName[0]; user.avatarURL = avatarURL[0]; user.username = username[0]; if (text.Count > 0) user.mostRecentTweet = text[0]; user.location = location[0]; user.bio = bio[0]; if (website.Count > 0) user.websiteURL = website[0]; else user.websiteURL = null; user.joinDate = joinDate[0]; user.verified = Convert.ToBoolean(verified[0]); user.followers = int.Parse(followers[0]); user.totalTweets = int.Parse(totalTweets[0]); if (!zombie) caller.templeHead(avatarURL[0],user); else caller.MakeZombie(user); }
public static void GetUserTimeline(string name, string AccessToken, int count, twitterButton caller) { Dictionary<string, string> headers = new Dictionary<string, string>(); headers["Authorization"] = "Bearer " + AccessToken; WWW web = new WWW("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" + name + "&count=" + count + "&trim_user=1" + "&include_rts=0&exclude_replies=true&contributor_details=false", null, headers); while (!web.isDone) { Debug.Log("Grabbing timeline..."); } //find user mentions List<string> mentions = extractData(web.text, ",\"user_mentions\":", ",\"urls\":"); //remove if true string extractMe; if (ammendOutputText == null) extractMe = web.text; else extractMe = ammendOutputText; Debug.Log("Extracting profile data..."); List<string> dateTime = extractData(extractMe, "{\"created_at\":\"", "\",\"id\":"); List<string> text = extractData(extractMe, ",\"text\":\"", ",\"truncated\":"); List<string> favs = extractData(extractMe, "\"favorite_count\":", ",\"entities\":"); List<string> RTs = extractData(extractMe, "\"retweet_count\":", ",\"favorite_count\":"); List<string> userID = extractData(extractMe, "\"user\":{\"id\":", "\"},\"geo\":"); List<string> tweetID = extractData(extractMe, ",\"id\":", "\",\"text\":"); List<Tweet> tweets = new List<Tweet>(); //format datetime // //For each time a space is detected, //do things with boop[2] for (int i = 0; i < text.Count; i++) { Tweet thisTweet = new Tweet(); #region dateTime formating string temp = ""; List<string> boop = new List<string>(); for (int k = 0; k < dateTime[i].Length; k++) { if (dateTime[i][k] != ' ') temp += dateTime[i][k]; else { boop.Add(temp); temp = ""; } if (k == dateTime[i].Length - 1) boop.Add(temp); } temp = ""; List<string> doop = new List<string>(); for (int k = 0; k < boop[3].Length; k++) { if (boop[3][k] != ':') temp += boop[3][k]; else { doop.Add(temp); temp = ""; } if (k == boop[3].Length - 1) doop.Add(temp); } tw_DateTime time = new tw_DateTime(); time.Weekday = boop[0]; time.Month = boop[1]; time.Day = boop[2]; time.Hour = doop[0]; time.Minute = doop[1]; time.Second = doop[2]; time.Year = boop[3]; time.Offset = boop[4]; #endregion thisTweet.dateTime = time; thisTweet.Text = text[i]; thisTweet.UserID = userID[i].Substring(0, userID[i].IndexOf(",\"id_str")); thisTweet.RTs = int.Parse(RTs[i]); thisTweet.Favs = int.Parse(favs[i]); thisTweet.ID = tweetID[i].Substring(0, tweetID[i].IndexOf(",\"id_str")); tweets.Add(thisTweet); } caller.tweets = tweets; ammendOutputText = null; }
void Awake() { gullNames = Regex.Split(gullNamesFile.text, "\n"); m_instance = this; LoadTwitterUserInfo(); }
//Grab a selection of tweets from a user public static void GetUserTimeline(string name, string AccessToken, int count, twitterButton caller) { //Set-up API call Dictionary<string, string> headers = new Dictionary<string, string>(); headers["Authorization"] = "Bearer " + AccessToken; //DO AN API CALL //For this program, the parameters used below will likely need to be changed bar username and # of tweets to pull WWW web = new WWW("https://api.twitter.com/1.1/statuses/" + "user" + "_timeline.json?screen_name=" + name + "&count=" + count + "&trim_user=1" + "&include_rts=0&exclude_replies=true&contributor_details=false", null, headers); while (!web.isDone) { Debug.Log("Processing request..."); } //We have an error x( if (web.error != null) { //Output error to UI GameObject.Find("Error Text").GetComponent<Text>().enabled = true; GameObject.Find("Error Text").GetComponent<Text>().text = web.error; } else { //We good GameObject.Find("Error Text").GetComponent<Text>().text = ""; //Remove this bit 'cause it's more trouble than it's worth. List<string> mentions = extractData(web.text, ",\"entities\":", ",\"source\":"); //If detected, remove. string extractMe; if (ammendOutputText == null) extractMe = web.text; else extractMe = ammendOutputText; string[] delim = { "},{" }; string[] pls = extractMe.Split(delim, StringSplitOptions.None); foreach (string s in pls) { string temp = s; if (temp.StartsWith("[")) temp=temp.Remove(0, 1); if (temp.EndsWith("]") || temp.EndsWith("}}")) temp = temp.Remove(temp.Length - 1, 1); if (!temp.EndsWith("}")) temp += "}"; if (!temp.StartsWith("{")) temp = "{" + temp; Tweet newTweet = JsonUtility.FromJson<Tweet>(temp); newTweet.FormattedDateTime = formatDateTime(newTweet.created_at); newTweet.screen_name = currentDisplayName; caller.tweets.Add(newTweet); } #region old method of data extraction /* List<string> dateTime = extractData(extractMe, "{\"created_at\":\"", "\",\"id\":"); List<string> text = extractData(extractMe, ",\"text\":\"", "\",\"truncated\":"); List<string> favs = extractData(extractMe, "\"favorite_count\":", ",\"favorited\":"); List<string> RTs = extractData(extractMe, "\"retweet_count\":", ",\"favorite_count\":"); List<string> userID = extractData(extractMe, "\"user\":{\"id\":", "\"},\"geo\":"); List<string> tweetID = extractData(extractMe, ",\"id\":", "\",\"text\":"); //This is what will be used to create islands List<Tweet> tweets = new List<Tweet>(); //For each detected tweet for (int i = 0; i < text.Count; i++) { //Create a new tweet Tweet thisTweet = new Tweet(); #region dateTime formatting string temp = ""; List<string> date = new List<string>(); for (int k = 0; k < dateTime[i].Length; k++) { if (dateTime[i][k] != ' ') temp += dateTime[i][k]; else { date.Add(temp); temp = ""; } if (k == dateTime[i].Length - 1) date.Add(temp); } temp = ""; List<string> timeOfDay = new List<string>(); for (int k = 0; k < date[3].Length; k++) { if (date[3][k] != ':') temp += date[3][k]; else { timeOfDay.Add(temp); temp = ""; } if (k == date[3].Length - 1) timeOfDay.Add(temp); } tw_DateTime time = new tw_DateTime(); time.Weekday = date[0]; time.Month = date[1]; time.Day = int.Parse(date[2]); time.Hour = int.Parse(timeOfDay[0]); time.Minute = int.Parse(timeOfDay[1]); time.Second = int.Parse(timeOfDay[2]); time.Year = int.Parse(date[5]); time.Offset = date[4]; #endregion //Add data to tweet thisTweet.dateTime = time; thisTweet.Text = text[i]; thisTweet.UserID = userID[i].Substring(0, userID[i].IndexOf(",\"id_str")); thisTweet.RTs = int.Parse(RTs[i]); thisTweet.Favs = int.Parse(favs[i]); thisTweet.ID = tweetID[i].Substring(0, tweetID[i].IndexOf(",\"id_str")); thisTweet.DisplayName = currentDisplayName; //Add tweet tweets.Add(thisTweet); } //Send the tweet data back to the button used to call this function caller.tweets = tweets; ammendOutputText = null;*/ #endregion } }
public static IEnumerator GetRequestToken(string consumerKey, string consumerSecret, twitterButton caller) { WWW web = WWWRequestToken(consumerKey, consumerSecret); yield return web; if (!string.IsNullOrEmpty(web.error)) { Debug.Log(string.Format("GetRequestToken - failed. error : {0}", web.error)); } else { RequestTokenResponse response = new RequestTokenResponse { Token = Regex.Match(web.text, @"oauth_token=([^&]+)").Groups[1].Value, TokenSecret = Regex.Match(web.text, @"oauth_token_secret=([^&]+)").Groups[1].Value, }; if (!string.IsNullOrEmpty(response.Token) && !string.IsNullOrEmpty(response.TokenSecret)) { Twitter.API.OpenAuthorizationPage(response.Token); caller.m_RequestTokenResponse = response; } else { Debug.Log(string.Format("GetRequestToken - failed. response : {0}", web.text)); } } }
//Retrieve user profile information public static void GetProfile(string name, string AccessToken, twitterButton caller) { //Set-up API call Dictionary<string, string> headers = new Dictionary<string, string>(); headers["Authorization"] = "Bearer " + AccessToken; //DO AN API CALL //For this program, the parameters used below will likely need to be changed bar username and # of tweets to pull WWW web = new WWW("https://api.twitter.com/1.1/users/show.json?screen_name=" + name + "&include_entities=false", null, headers); while (!web.isDone) { Debug.Log("Processing request..."); } //We have an error x( if (web.error != null) { //Output error to UI GameObject.Find("Error Text").GetComponent<Text>().enabled = true; GameObject.Find("Error Text").GetComponent<Text>().text = web.error; Debug.Log(web.error); } else { TwitterUserInfo test = JsonUtility.FromJson<TwitterUserInfo>(web.text); caller.testObject = test; if (test.screen_name == " ") test.screen_name = "Somebody with a non-ascii name"; caller.verified = test.verified; test.profile_image_url = test.profile_image_url.Remove(test.profile_image_url.IndexOf("_normal"), 7); caller.StartCoroutine(twitterButton.setAvatar(test.profile_image_url)); currentDisplayName = test.screen_name; //We good GameObject.Find("Error Text").GetComponent<Text>().text = ""; } }