c# - Integrate twitter in windows phone 8 app -
i developing windows phone 8 application, in need integrate twitter. tried many ways got in search.
so please me out if used it.
thanks in advance.
edit
using tweetsharp; using system.io.isolatedstorage; public partial class mainpage : phoneapplicationpage { twitterservice service; private const string consumerkey = "some key"; private const string consumersecret = "some key1"; private oauthrequesttoken requesttoken; private oauthaccesstoken accestoken; private bool userauthenticated = false; public mainpage() { initializecomponent(); service = new twitterservice(consumerkey, consumersecret); //chek if have autehntification data var token = getaccesstoken(); if (token != null) { service.authenticatewith(token.token, token.tokensecret); userauthenticated = true; } } private void tweetclick(object sender, routedeventargs e) { if (userauthenticated) tweet(message.text); else service.getrequesttoken(processrequesttoken); } private void processrequesttoken(oauthrequesttoken token, twitterresponse response) { if (token == null) dispatcher.begininvoke(() => { messagebox.show("error obtaining request token"); }); else { requesttoken = token; dispatcher.begininvoke(() => { browser.visibility = system.windows.visibility.visible; browser.navigate(service.getauthorizationuri(requesttoken)); }); } } private void processaccesstoken(oauthaccesstoken token, twitterresponse response) { if (token == null) dispatcher.begininvoke(() => { messagebox.show("error obtaining access token"); }); else { accestoken = token; service.authenticatewith(token.token, token.tokensecret); saveaccesstoken(token); userauthenticated = true; dispatcher.begininvoke(() => { tweet(message.text); }); } } private void tweet(string message) { service.sendtweet(message, tweetresponse); } private void tweetresponse(twitterstatus tweet, twitterresponse response) { if (response.statuscode == httpstatuscode.ok) { dispatcher.begininvoke(() => { messagebox.show("tweet posted successfully"); }); } else { if (response.statuscode == httpstatuscode.unauthorized) { saveaccesstoken(null); userauthenticated = false; dispatcher.begininvoke(() => { messagebox.show("authentication error"); }); } else dispatcher.begininvoke(() => { messagebox.show("error, please try again later"); }); } } private void browsernavitaged(object sender, system.windows.navigation.navigationeventargs e) { if (e.uri.absoluteuri.contains("oauth_verifier")) { var values = parsequerystring(e.uri.absoluteuri); string verifier = values["oauth_verifier"]; service.getaccesstoken(requesttoken, verifier, processaccesstoken); dispatcher.begininvoke(() => { browser.visibility = system.windows.visibility.collapsed; }); } } private void saveaccesstoken(oauthaccesstoken token) { if (isolatedstoragesettings.applicationsettings.contains("accesstoken")) isolatedstoragesettings.applicationsettings["accesstoken"] = token; else isolatedstoragesettings.applicationsettings.add("accesstoken", token); isolatedstoragesettings.applicationsettings.save(); } private oauthaccesstoken getaccesstoken() { if (isolatedstoragesettings.applicationsettings.contains("accesstoken")) return isolatedstoragesettings.applicationsettings["accesstoken"] oauthaccesstoken; else return null; } protected override void onbackkeypress(system.componentmodel.canceleventargs e) { if (browser.visibility == system.windows.visibility.visible) { browser.visibility = system.windows.visibility.collapsed; e.cancel = true; } base.onbackkeypress(e); } // hammock.extensions.stringextensions.cs public static idictionary<string, string> parsequerystring(string query) { // [dc]: method not url decode, , cannot handle decoded input if (query.startswith("?")) query = query.substring(1); if (query.equals(string.empty)) { return new dictionary<string, string>(); } var parts = query.split(new[] { '&' }); return parts.select( part => part.split(new[] { '=' })).todictionary( pair => pair[0], pair => pair[1] ); } }
here posted code tried. m getting error on "getaccesstoken" saying "does not contain definition getaccesstoken... "
Comments
Post a Comment