// We only unfollow if nobody is subscribed anymore public async Task UnfollowUser(long userId, string discordName) { var RelevantUser = await UserAsync.GetUserFromId(userId); // For some reason, User has an unfollow method but UserAsync doesn't User.UnFollowUser(RelevantUser); }
public async Task AddFriendsToList() { //var userId = "rkgk_mochi_112"; foreach (var targetName in new[] { "zombie_haruna", "zombie_you" }) { var me = await UserAsync.GetAuthenticatedUser(cred); var listName = $"home-{targetName}"; var twitterList = TwitterList.CreateList(listName, PrivacyMode.Private, "Just for test of my application."); var target = await UserAsync.GetUserFromScreenName(targetName); if (targetName.Contains("haruna")) { var users = await UserAsync.GetFriendIds(target, maxFriendsToRetrieve : 100); foreach (var userId in users) { var result = twitterList.AddMember(userId); Debug.WriteLine(result); } } else { continue; } } }
public async Task <ITweet> GetLatestTweetFromTimeline(string name) { var user = await UserAsync.GetUserFromScreenName(name); var timeline = Timeline.GetUserTimeline(user.Id); return(timeline.FirstOrDefault()); }
public async Task <ActionResult> Index() { Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET"); var user = await UserAsync.GetAuthenticatedUser(); ViewBag.User = user.Name; return(View()); }
public static void Main(string[] args) { Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET"); var user = UserAsync.GetAuthenticatedUser().Result; System.Console.WriteLine(user); System.Console.ReadKey(); }
public async Task <IEnumerable <Entities.User> > GetFriendsAsync(string userId) { var users = await Auth.ExecuteOperationWithCredentials( this.credentials, () => UserAsync.GetFriends(long.Parse(userId))); var mapper = new UserMapper(); return(users.Select(user => mapper.Map(user, new Entities.User()))); }
public virtual async Task <Entities.User> GetAsync(string userId) { var user = await Auth.ExecuteOperationWithCredentials( this.credentials, () => UserAsync.GetUserFromId(long.Parse(userId))); var mapper = new UserMapper(); return(mapper.Map(user, new Entities.User())); }
public async Task <IActionResult> GetUser(string screenName) { var user = await Auth.ExecuteOperationWithCredentials(creds, () => { return(UserAsync.GetUserFromScreenName(screenName)); }); return(Ok(user)); }
private async Task <IEnumerable <ITweet> > GetPostsByUserTimeline( IUser author, int maximumResults) { Tweetinvi.Models.IUser user = await _executer .Execute(() => UserAsync.GetUserFromId(author.Id)); return(await _executer .Execute(() => user.GetUserTimelineAsync(maximumResults))); }
protected override async void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button>(Resource.Id.MyButton); Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET"); var user = await UserAsync.GetAuthenticatedUser(); button.Click += delegate { button.Text = string.Format("{0} clicked {1} times!", user, count++); }; }
public override async Task <GetTwitterUserResponse> GetTwitterUser(GetTwitterUserRequest request, ServerCallContext context) { GetTwitterUserResponse response = new GetTwitterUserResponse(); response.User = new TwitterUser { Language = request.Language, VoiceName = request.VoiceName }; IUser user = request.UserCase switch { GetTwitterUserRequest.UserOneofCase.Id => await UserAsync.GetUserFromId(request.Id), GetTwitterUserRequest.UserOneofCase.Handle => await UserAsync.GetUserFromScreenName(request.Handle), _ => null, }; response.User.Id = user.Id; response.User.Handle = user.ScreenName; response.User.Name = user.Name; response.User.ProfileImageUrl = user.ProfileImageUrlFullSize; return(response); }
public Task <IUser> GetUserAsync(string name) => GetUserFromTwitter(() => UserAsync.GetUserFromScreenName(name));
public async Task AlertUnsubscribedUser(long userId, string discordName) { var RelevantUser = await UserAsync.GetUserFromId(userId); await TweetAsync.PublishTweet($"@{RelevantUser.ScreenName}: {discordName} has requested that Switch screenshots from you are no longer PMed to them."); }
public async Task <string> GetUsername(long userId) { var RelevantUser = await UserAsync.GetUserFromId(userId); return(RelevantUser.ScreenName); }
public async Task SetUserConnected() { var user = await UserAsync.GetLoggedUser(); UserLogged = AutoMapper.Mapper.Map <Models.TwitterUser> (user); }
protected async Task <TrainSet> ScheduleProcessTwitter(TrainSet data) { var collection = await _twitterCollectionsStore.Get(data.SourceId); if (collection == null) { data.SetFailed("Can not find source data"); return(data); } var sources = await _twitterSourcesStore.GetBy(x => x.CollectionId == collection.Id); if (sources == null || !sources.Any()) { data.SetFailed("Can not find any twitter sources"); return(data); } var user = await _userStore.FindByIdAsync(collection.UserId); if (user == null) { data.SetFailed("Can not find user data"); return(data); } var userTwitter = await _userSocialsStore.GetTwitter(user.Id); if (userTwitter == null) { data.SetFailed("No twitter access token"); return(data); } try { OAuthTwitter(userTwitter); } catch { data.SetFailed("Error with twitter connections"); return(data); } // upload twitter data int min = data.MinCount; min = Math.Max(1, min); int max = data.MaxCount; max = Math.Max(100, max); max = Math.Min(10000, max); if (min > max) { var t = min; max = min; min = t; } int perSource = (int)Math.Ceiling((double)max / sources.Count); var entity = new TrainSetModel { }; var rawData = new StringBuilder(); int total = 0; var regex = new Regex("http[s]?://[A-Za-z0-9._-]*"); foreach (var screen in sources) { long?lastId = null; int count = 0; var twetterUser = await UserAsync.GetUserFromId(screen.TwitterId); while (perSource > count) { var @params = new UserTimelineParameters { MaximumNumberOfTweetsToRetrieve = 50, }; if (lastId.HasValue) { @params.SinceId = lastId.Value; } var tweets = await TimelineAsync.GetUserTimeline(twetterUser, @params); if (tweets == null || !tweets.Any()) { break; } count += tweets.Count(); foreach (var t in tweets) { rawData.Append(regex.Replace(t.FullText, string.Empty)); } } total += count; } if (total < min) { data.SetFailed($"Not enough data avaliable. Avaliable : {total}. Minimum: {min}"); return(data); } WordBag wb = WordBag.CreateToWords(rawData.ToString(), data.InputWordsCount + 1); _vReader.UploadBinary(); List <Tuple <string[], string[]> > stringList = new List <Tuple <string[], string[]> >(); List <Tuple <double[], double[]> > doubleList = new List <Tuple <double[], double[]> >(); foreach (var s in wb.Read()) { var vectorList = new List <double[]>(); var wordList = new List <string>(); foreach (var ss in s) { var word = _vReader.Vocab.GetRepresentationOrNullFor(ss); if (word == null) { break; } vectorList.Add(ss.Select(x => (double)x).ToArray()); wordList.Add(ss); } if (vectorList.Count < s.Length) { continue; } var tmpVector = new List <double>(); foreach (var i in vectorList.Take(data.InputWordsCount)) { tmpVector.AddRange(i); } doubleList.Add(new Tuple <double[], double[]>(tmpVector.ToArray(), vectorList.Last().ToArray())); stringList.Add(new Tuple <string[], string[]>(wordList.Take(wordList.Count - 1).ToArray(), new string[1] { wordList.Last() })); } entity.Data = doubleList.ToArray(); entity.StringSource = stringList.ToArray(); string dataString = JsonConvert.SerializeObject(entity); await _storageBlobClient.SetContainer(CONTAINER_NAME, true); var storageKey = await _storageBlobClient.WriteText(dataString); if (string.IsNullOrWhiteSpace(storageKey)) { data.SetFailed("Can not upload train set to storage"); return(data); } data.StorageKey = storageKey; data.SetReady(); data.ExamplesCount = entity.Data.Count(); return(data); }
public async Task OnGet([FromQuery(Name = "id")] string twitterId, [FromQuery] bool DoIt = false) { if (string.IsNullOrEmpty(twitterId)) { Redirect("/Error"); } var sw = new Stopwatch(); var(consumerKey, consumerSecret, accessToken, accessTokenSecret) = await GetTwitterAuthKeys(); ExceptionHandler.SwallowWebExceptions = false; Auth.SetUserCredentials(consumerKey, consumerSecret, accessToken, accessTokenSecret); LoggedInTwitterId = (await UserAsync.GetAuthenticatedUser()).ScreenName; TwitterId = twitterId; ListName = $"private_{twitterId}"; // Ensure that we can get some information sw.Start(); var usersFriends = await Tweetinvi.UserAsync.GetFriendIds(twitterId, 5000); sw.Stop(); ListMemberCount = usersFriends.Count() + 1; _logger.LogInformation($"TweetInvi command ({sw.ElapsedMilliseconds}ms) UserAsync.GetFriendIds() for {{{twitterId}}} found {ListMemberCount} friends"); var membersToAdd = usersFriends.Select(f => new UserIdentifier(f)); var list = await TwitterListAsync.GetExistingList(ListNameSlug, LoggedInTwitterId); if (list == null) { list = await TwitterListAsync.CreateList( ListName, PrivacyMode.Private, $"The list of accounts that @{twitterId} follows as of {DateTime.UtcNow.ToLongDateString()}. Should have {membersToAdd.Count()} members."); _logger.LogInformation($"Created list {{{ListName}}}."); } else { TwitterListUpdateParameters updateParameter = new TwitterListUpdateParameters() { // Name = ListName, // PrivacyMode = PrivacyMode.Private, Description = $"The list of accounts that @{twitterId} follows as of {DateTime.UtcNow.ToLongDateString()}. Should have {membersToAdd.Count()} members." }; sw.Restart(); var existingMembers = await list.GetMembersAsync(5000); sw.Stop(); _logger.LogInformation($"TweetInvi command ({sw.ElapsedMilliseconds}ms) list.GetMembersAsync() for {{{list.Slug}}} found {existingMembers.Count()} members"); membersToAdd = membersToAdd.Where(m => !existingMembers.Any(existing => m.Id == existing.Id)); if (DoIt || !_env.IsDevelopment()) { var success = await list.UpdateAsync(updateParameter); if (success) { _logger.LogInformation($"Updated description of {{{ListName}}}."); } else { _logger.LogError($"Updating description of {{{ListName}}} failed."); } } } NoOfMembersToAdd = membersToAdd.Count(); // Need to limit to 5000 accounts if (DoIt || !_env.IsDevelopment()) { await list.AddMemberAsync(await UserAsync.GetUserFromScreenName(twitterId)); sw.Restart(); var result = await list.AddMultipleMembersAsync(membersToAdd); sw.Stop(); ResponseString = result.ToString(); if (result == MultiRequestsResult.Success) { _logger.LogInformation($"TweetInvi command ({sw.ElapsedMilliseconds}ms) list.AddMultipleMembersAsync() for {{{list.Slug}}} adding {membersToAdd.Count()} members finished with result: {result}"); } else { _logger.LogError($"TweetInvi command ({sw.ElapsedMilliseconds}ms) list.AddMultipleMembersAsync() for {{{list.Slug}}} adding {membersToAdd.Count()} members finished with result: {result}"); } } else { _logger.LogWarning($"DEV MODE: AddMultipleMembersToList: Didn't add {membersToAdd.Count()} to list {{{ListName}}}."); ResponseString = "Nothing added in Development Mode"; } sw.Restart(); NoOfActualMembers = (await list.GetMembersAsync(5000)).Count(); sw.Stop(); _logger.LogInformation($"TweetInvi command ({sw.ElapsedMilliseconds}ms) list.GetMembersAsync() for {{{list.Slug}}} found {NoOfActualMembers} members"); var rateLimits = await RateLimitAsync.GetCurrentCredentialsRateLimits(); }
public Task <IUser> GetUserAsync(long userId) => GetUserFromTwitter(() => UserAsync.GetUserFromId(userId));
public Task <IUser> GetIdentityAsync() => GetUserFromTwitter(async() => (Tweetinvi.Models.IUser) await UserAsync.GetAuthenticatedUser());