Informationen:
Der BlueFLAG Twitter Client entstand im Rahmen eines eigenen Projekts.
Beta und keine Veröffentlichung.
Im Vordergrund stand lediglich der Spaß an der Programmierung und dem Zusammenspiel mit Twitter.
Funktionen:
- Tweets veröffentlichen
- Nachrichten [senden / lesen]
- Tweets lesen [own / timeline]
- Twitter Einstellungen ändern
- Follower
- Following
- Auto Update der Tweets, Follower, Following und Nachrichten
- Links in Tweets öffnen den Browser
Code-Behind-Auszüge:
HomeTimeline
public List getHomeTimeline(String access,
String saccess, TwitterService service)
{
IEnumerable tweets = service.ListTweetsOnHomeTimeline(30);
var tweeet = (from tweet in tweets
select new Tweet()
{
Image = tweet.User.ProfileImageUrl,
Text = tweet.Text
}).Take(30).ToList();
return tweeet;
}
Link Finder
namespace Twitter
{
public static class LinkFinder
{
private static readonly Regex RE_URL = new Regex(@"(?#Protocol)(?:(?:ht|f)tp(?:s?)\:\/\/|~/|/)?(?#Username:Password)(?:\w+:\w+@)?(?#Subdomains)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(?#Port)(?::[\d]{1,5})?(?#Directories)(?:(?:(?:/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|/)+|\?|#)?(?#Query)(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)?");
public static readonly DependencyProperty TextProperty = DependencyProperty.RegisterAttached(
"Text",
typeof(string),
typeof(LinkFinder),
new PropertyMetadata(null, OnTextChanged)
);
public static string GetText(DependencyObject d)
{ return d.GetValue(TextProperty) as string; }
public static void SetText(DependencyObject d, string value)
{ d.SetValue(TextProperty, value); }
private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var text_block = d as TextBlock;
if (text_block == null)
return;
text_block.Inlines.Clear();
var new_text = (string)e.NewValue;
if (string.IsNullOrEmpty(new_text))
return;
int last_pos = 0;
foreach (Match match in RE_URL.Matches(new_text))
{
if (match.Index != last_pos)
{
var raw_text = new_text.Substring(last_pos, match.Index - last_pos);
text_block.Inlines.Add(new Run(raw_text));
}
try
{
var link = new Hyperlink(new Run(match.Value))
{
NavigateUri = new Uri(match.Value)
};
link.Click += OnUrlClick;
text_block.Inlines.Add(link);
last_pos = match.Index + match.Length;
}
catch (UriFormatException) { }
}
if (last_pos < new_text.Length)
text_block.Inlines.Add(new Run(new_text.Substring(last_pos)));
}
private static void OnUrlClick(object sender, RoutedEventArgs e)
{
var link = (Hyperlink)sender;
Process.Start(link.NavigateUri.ToString());
}
}
}
Authentifikation
namespace Twitter
{
class Authentifikation
{
public String _consumerKey { get; set; }
public String _consumerSecret { get; set; }
public String _accessToken { get; set; }
public String _accessTokenSecret { get; set; }
TwitterService service = new TwitterService();
OAuthRequestToken requestToken;
Twitter.Settings1 settings = new Settings1();
public String _pin;
public void setPin(String pin) {
_pin = pin;
}
public void requestPin(){
service = new TwitterService("lirfzRwMR29NpmJJuMsgA", "sBRsgEZ7FilYnICZ7XAMobtGDj10B89oIEK2e8BvXZc");
requestToken = service.GetRequestToken();
Uri uri = service.GetAuthenticationUrl(requestToken);
Process.Start(uri.ToString());
}
public void loadTokens() {
_accessToken = settings.access;
_accessTokenSecret = settings.saccess;
}
public void responseService()
{
string verifier = _pin;
try
{
OAuthAccessToken access = service.GetAccessToken(requestToken, verifier);
_accessToken = access.Token;
_accessTokenSecret = access.TokenSecret;
settings.access = _accessToken;
settings.saccess = _accessTokenSecret;
settings.Save();
}
catch (NullReferenceException e) { Console.WriteLine(e); }
}
}
}


