我想转换一个推文网址,例如https://twitter.com/LindseyGrahamSC/status/320202348263780352以便它自动嵌入。到目前为止,我想出的最好的方法是使用像 [tweet:320202348263780352] 这样的短代码类型语法,然后生成嵌入的推文。但我真的很想将网址粘贴进去并让它工作。我对如何实现这一目标感到困惑。到目前为止我所拥有的:
var ctxTwitterContext = new TwitterContext(auth);
if (e.Location != ServingLocation.PostList && e.Location != ServingLocation.SinglePost)
return;
string regex__1 = @"\[tweet:.*?\]";
MatchCollection matches = Regex.Matches(e.Body, regex__1);
for (int i = 0; i < matches.Count; i++)
{
Int32 length = "[tweet:".Length;
string TweetID = matches[i].Value.Substring(length, matches[i].Value.Length - length - 1);
var embeddedStatus =
(from tweet in ctxTwitterContext.Status
where tweet.Type == StatusType.Oembed &&
tweet.ID == TweetID
select tweet.EmbeddedStatus)
.SingleOrDefault();
string html = embeddedStatus.Html;
e.Body = e.Body.Replace(matches[i].Value, String.Format(html));