added media
This commit is contained in:
parent
068f0af344
commit
35bc724c92
2 changed files with 42 additions and 23 deletions
|
@ -202,6 +202,25 @@ namespace BirdsiteLive.Twitter
|
||||||
string creationTime = tweet.GetProperty("content").GetProperty("itemContent")
|
string creationTime = tweet.GetProperty("content").GetProperty("itemContent")
|
||||||
.GetProperty("tweet_results").GetProperty("result").GetProperty("legacy")
|
.GetProperty("tweet_results").GetProperty("result").GetProperty("legacy")
|
||||||
.GetProperty("created_at").GetString().Replace(" +0000", "");
|
.GetProperty("created_at").GetString().Replace(" +0000", "");
|
||||||
|
|
||||||
|
JsonElement extendedEntities;
|
||||||
|
bool hasMedia = tweet.GetProperty("content").GetProperty("itemContent")
|
||||||
|
.GetProperty("tweet_results").GetProperty("result").GetProperty("legacy")
|
||||||
|
.TryGetProperty("extended_entities", out extendedEntities);
|
||||||
|
|
||||||
|
List<ExtractedMedia> Media = new List<ExtractedMedia>();
|
||||||
|
if (hasMedia)
|
||||||
|
{
|
||||||
|
foreach (JsonElement media in extendedEntities.GetProperty("media").EnumerateArray())
|
||||||
|
{
|
||||||
|
var m = new ExtractedMedia
|
||||||
|
{
|
||||||
|
MediaType = GetMediaType(media.GetProperty("type").GetString(), media.GetProperty("media_url_https").GetString()),
|
||||||
|
Url = media.GetProperty("media_url_https").GetString(),
|
||||||
|
};
|
||||||
|
Media.Add(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
var extractedTweet = new ExtractedTweet
|
var extractedTweet = new ExtractedTweet
|
||||||
{
|
{
|
||||||
Id = Int64.Parse(tweet.GetProperty("sortIndex").GetString()),
|
Id = Int64.Parse(tweet.GetProperty("sortIndex").GetString()),
|
||||||
|
@ -212,7 +231,7 @@ namespace BirdsiteLive.Twitter
|
||||||
IsReply = isReply,
|
IsReply = isReply,
|
||||||
IsThread = false,
|
IsThread = false,
|
||||||
IsRetweet = isRetweet,
|
IsRetweet = isRetweet,
|
||||||
Media = null,
|
Media = Media.Count() == 0 ? null : Media.ToArray(),
|
||||||
RetweetUrl = "https://t.co/123",
|
RetweetUrl = "https://t.co/123",
|
||||||
OriginalAuthor = OriginalAuthor,
|
OriginalAuthor = OriginalAuthor,
|
||||||
};
|
};
|
||||||
|
|
|
@ -56,10 +56,30 @@ namespace BirdsiteLive.Twitter
|
||||||
var c = await httpResponse.Content.ReadAsStringAsync();
|
var c = await httpResponse.Content.ReadAsStringAsync();
|
||||||
res = JsonDocument.Parse(c);
|
res = JsonDocument.Parse(c);
|
||||||
}
|
}
|
||||||
|
var result = res.RootElement.GetProperty("data").GetProperty("user").GetProperty("result");
|
||||||
|
string profileBannerURL = null;
|
||||||
|
JsonElement profileBannerURLObject;
|
||||||
|
if (result.GetProperty("legacy").TryGetProperty("profile_banner_url", out profileBannerURLObject))
|
||||||
|
{
|
||||||
|
profileBannerURL = profileBannerURLObject.GetString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TwitterUser
|
||||||
|
{
|
||||||
|
Id = long.Parse(result.GetProperty("rest_id").GetString()),
|
||||||
|
Acct = username,
|
||||||
|
Name = result.GetProperty("legacy").GetProperty("name").GetString(), //res.RootElement.GetProperty("data").GetProperty("name").GetString(),
|
||||||
|
Description = "", //res.RootElement.GetProperty("data").GetProperty("description").GetString(),
|
||||||
|
Url = "", //res.RootElement.GetProperty("data").GetProperty("url").GetString(),
|
||||||
|
ProfileImageUrl = result.GetProperty("legacy").GetProperty("profile_image_url_https").GetString().Replace("normal", "400x400"),
|
||||||
|
ProfileBackgroundImageUrl = profileBannerURL,
|
||||||
|
ProfileBannerURL = profileBannerURL,
|
||||||
|
Protected = false, //res.RootElement.GetProperty("data").GetProperty("protected").GetBoolean(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
catch (HttpRequestException e)
|
catch (System.Collections.Generic.KeyNotFoundException)
|
||||||
{
|
{
|
||||||
throw;
|
throw new UserNotFoundException();
|
||||||
//if (e.TwitterExceptionInfos.Any(x => x.Message.ToLowerInvariant().Contains("User has been suspended".ToLowerInvariant())))
|
//if (e.TwitterExceptionInfos.Any(x => x.Message.ToLowerInvariant().Contains("User has been suspended".ToLowerInvariant())))
|
||||||
//{
|
//{
|
||||||
// throw new UserHasBeenSuspendedException();
|
// throw new UserHasBeenSuspendedException();
|
||||||
|
@ -88,26 +108,6 @@ namespace BirdsiteLive.Twitter
|
||||||
//foreach (var descriptionUrl in user.Entities?.Description?.Urls?.OrderByDescending(x => x.URL.Length))
|
//foreach (var descriptionUrl in user.Entities?.Description?.Urls?.OrderByDescending(x => x.URL.Length))
|
||||||
// description = description.Replace(descriptionUrl.URL, descriptionUrl.ExpandedURL);
|
// description = description.Replace(descriptionUrl.URL, descriptionUrl.ExpandedURL);
|
||||||
|
|
||||||
var result = res.RootElement.GetProperty("data").GetProperty("user").GetProperty("result");
|
|
||||||
string profileBannerURL = null;
|
|
||||||
JsonElement profileBannerURLObject;
|
|
||||||
if (result.GetProperty("legacy").TryGetProperty("profile_banner_url", out profileBannerURLObject))
|
|
||||||
{
|
|
||||||
profileBannerURL = profileBannerURLObject.GetString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new TwitterUser
|
|
||||||
{
|
|
||||||
Id = long.Parse(result.GetProperty("rest_id").GetString()),
|
|
||||||
Acct = username,
|
|
||||||
Name = result.GetProperty("legacy").GetProperty("name").GetString(), //res.RootElement.GetProperty("data").GetProperty("name").GetString(),
|
|
||||||
Description = "", //res.RootElement.GetProperty("data").GetProperty("description").GetString(),
|
|
||||||
Url = "", //res.RootElement.GetProperty("data").GetProperty("url").GetString(),
|
|
||||||
ProfileImageUrl = result.GetProperty("legacy").GetProperty("profile_image_url_https").GetString().Replace("normal", "400x400"),
|
|
||||||
ProfileBackgroundImageUrl = profileBannerURL,
|
|
||||||
ProfileBannerURL = profileBannerURL,
|
|
||||||
Protected = false, //res.RootElement.GetProperty("data").GetProperty("protected").GetBoolean(),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue