2020-03-21 18:58:23 -04:00
|
|
|
|
using System;
|
2020-03-22 01:29:51 -04:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using BirdsiteLive.Common.Settings;
|
|
|
|
|
using BirdsiteLive.Twitter.Models;
|
2020-03-21 23:55:49 -04:00
|
|
|
|
using Tweetinvi;
|
2020-07-01 22:45:43 -04:00
|
|
|
|
using Tweetinvi.Models;
|
2020-03-21 18:58:23 -04:00
|
|
|
|
|
|
|
|
|
namespace BirdsiteLive.Twitter
|
|
|
|
|
{
|
|
|
|
|
public interface ITwitterService
|
|
|
|
|
{
|
2020-03-22 01:29:51 -04:00
|
|
|
|
TwitterUser GetUser(string username);
|
2020-07-01 22:45:43 -04:00
|
|
|
|
ITweet GetTweet(long statusId);
|
2020-03-21 18:58:23 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TwitterService : ITwitterService
|
|
|
|
|
{
|
|
|
|
|
private readonly TwitterSettings _settings;
|
|
|
|
|
|
|
|
|
|
#region Ctor
|
|
|
|
|
public TwitterService(TwitterSettings settings)
|
|
|
|
|
{
|
|
|
|
|
_settings = settings;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2020-03-21 23:55:49 -04:00
|
|
|
|
|
2020-03-22 01:29:51 -04:00
|
|
|
|
public TwitterUser GetUser(string username)
|
2020-03-21 23:55:49 -04:00
|
|
|
|
{
|
2020-03-22 16:38:15 -04:00
|
|
|
|
//Auth.SetUserCredentials(_settings.ConsumerKey, _settings.ConsumerSecret, _settings.AccessToken, _settings.AccessTokenSecret);
|
|
|
|
|
Auth.SetApplicationOnlyCredentials(_settings.ConsumerKey, _settings.ConsumerSecret, true);
|
2020-03-21 23:55:49 -04:00
|
|
|
|
var user = User.GetUserFromScreenName(username);
|
2020-03-22 16:38:15 -04:00
|
|
|
|
if (user == null) return null;
|
2020-03-22 01:29:51 -04:00
|
|
|
|
|
|
|
|
|
return new TwitterUser
|
|
|
|
|
{
|
2020-03-22 16:38:15 -04:00
|
|
|
|
Acct = username,
|
2020-03-22 01:29:51 -04:00
|
|
|
|
Name = user.Name,
|
|
|
|
|
Description = user.Description,
|
2020-03-22 16:45:26 -04:00
|
|
|
|
Url = $"https://twitter.com/{username}",
|
2020-03-22 16:38:15 -04:00
|
|
|
|
ProfileImageUrl = user.ProfileImageUrlFullSize,
|
|
|
|
|
ProfileBackgroundImageUrl = user.ProfileBackgroundImageUrlHttps,
|
|
|
|
|
ProfileBannerURL = user.ProfileBannerURL
|
2020-03-22 01:29:51 -04:00
|
|
|
|
};
|
2020-03-21 23:55:49 -04:00
|
|
|
|
}
|
2020-07-01 22:45:43 -04:00
|
|
|
|
|
|
|
|
|
public ITweet GetTweet(long statusId)
|
|
|
|
|
{
|
|
|
|
|
Auth.SetApplicationOnlyCredentials(_settings.ConsumerKey, _settings.ConsumerSecret, true);
|
|
|
|
|
var tweet = Tweet.GetTweet(statusId);
|
|
|
|
|
return tweet;
|
|
|
|
|
}
|
2020-03-21 18:58:23 -04:00
|
|
|
|
}
|
|
|
|
|
}
|