Commit 4674bb73 authored by HankG's avatar HankG

Fix Twitter connector so uses ScreenName not ProfileId for timeline query

parent b292f7e6
......@@ -17,6 +17,7 @@ namespace MySocialPortalLib.Service.SocialMediaConnectors
public const string HomeTimelineName = "Home_B3F632BB-33D5-4E05-8BE7-2D61D69AE4D4";
public const ulong EarliestTweetValue = 1;
public const ulong LatestTweetValue = ulong.MaxValue;
private const string ScreenNameProperty = "ScreenName";
public IPersonsRepository PersonsRepository { get; }
......@@ -63,25 +64,30 @@ namespace MySocialPortalLib.Service.SocialMediaConnectors
public IEnumerable<Post> GetNewerUserTimeline(Person person, int maxPosts)
{
var twitterId = person?.SocialMediaAccounts[StandardSocialNetworkNames.Twitter]?.ProfileId;
if (twitterId == null)
var twitterId = "";
person?.SocialMediaAccounts[StandardSocialNetworkNames.Twitter]?.AdditionalProperties
.TryGetValue(ScreenNameProperty, out twitterId);
if(string.IsNullOrWhiteSpace(twitterId))
{
Console.WriteLine($"No Twitter user for person: {person.Id} {person.Name}");
return new List<Post>();
}
Console.WriteLine($"Getting newer Twitter posts from {person.Name} (@{twitterId})");
var newInterval = TimelineManager.GetNextSamplingInterval(twitterId, EarliestTweetValue, LatestTweetValue);
return PullUserTweets(twitterId, newInterval, maxPosts);
}
public IEnumerable<Post> GetOlderUserTimeline(Person person, int maxPosts)
{
var twitterId = person?.SocialMediaAccounts[StandardSocialNetworkNames.Twitter]?.ProfileId;
if (twitterId == null)
var twitterId = "";
person?.SocialMediaAccounts[StandardSocialNetworkNames.Twitter]?.AdditionalProperties
.TryGetValue(ScreenNameProperty, out twitterId);
if(string.IsNullOrWhiteSpace(twitterId))
{
Console.WriteLine($"No Twitter user for person: {person.Id} {person.Name}");
return new List<Post>();
}
Console.WriteLine($"Getting older Twitter posts from {person.Name} (@{twitterId})");
var newInterval = TimelineManager.GetPreviousSamplingInterval(twitterId, EarliestTweetValue, LatestTweetValue);
if (newInterval != null && newInterval.IntervalStop != ulong.MaxValue)
{
......@@ -186,10 +192,12 @@ namespace MySocialPortalLib.Service.SocialMediaConnectors
IQueryable<Status> query;
if (interval.IntervalStop == ulong.MaxValue)
{
Console.WriteLine($"Pulling tweets for Twitter user {username} with no upper bounds: {interval}");
query = GetNoUpperUserStatusQuery(username, interval, maxPosts);
}
else
{
Console.WriteLine($"Pulling tweets for Twitter user {username} with no upper and lower bounds: {interval}");
query = GetUpperLowerUserStatusQuery(username, interval, maxPosts);
}
......
......@@ -122,7 +122,8 @@ namespace MySocialPortalLibTest.Service.SocialMediaConnectors
{
Name = "Jack Dorsey"
};
jack.SocialMediaAccounts.Add(StandardSocialNetworkNames.Twitter, new SocialMediaAccountData{ProfileId = "jack", SocialMediaSystemName = StandardSocialNetworkNames.Twitter});
jack.SocialMediaAccounts.Add(StandardSocialNetworkNames.Twitter, new SocialMediaAccountData{ProfileId = "1234", SocialMediaSystemName = StandardSocialNetworkNames.Twitter});
jack.SocialMediaAccounts[StandardSocialNetworkNames.Twitter].AdditionalProperties.Add("ScreenName", "jack");
var tc = new TwitterConnector(GetTempPersonDb(), GetService());
var allPosts = new List<Post>();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment