private async void TwitterAuth_Completed(object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { Dictionary <string, string> param = new Dictionary <string, string>(); param.Add("include_email", "true"); var request = new OAuth1Request("GET", new Uri(Constants.TW_OAUTH_URI), param, e.Account); try { var response = await request.GetResponseAsync(); var json = response.GetResponseText(); var twitterUser = JsonConvert.DeserializeObject <TwitterUser>(json); string name = twitterUser.name; string email = twitterUser.email; string id = twitterUser.Id; RegisterResultCheck(name, email, "twitter_" + id); } catch { } } }
public async Task <SocialNetworkModel> GetSocialNetworkAsync(Account account) { try { var request = new OAuth1Request("GET", new Uri("https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true"), null, account); var response = await request.GetResponseAsync(); var json = response.GetResponseText(); TwitterModel twitterUser = JsonConvert.DeserializeObject <TwitterModel>(json); return(new SocialNetworkModel() { ID = twitterUser.Id, NUserName = twitterUser.Name, EmailAddress = twitterUser.Email, }); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } }
public async Task GetTwitterData(string socialId, string screenName) { var request = new OAuth1Request("GET", new Uri(Constants.TwitterProfileInfoURL), null, loggedInAccount); await request.GetResponseAsync().ContinueWith(t => { var res = t.Result; var resString = res.GetResponseText(); Console.WriteLine("Result Text: " + resString); var jo = Newtonsoft.Json.Linq.JObject.Parse(resString); string name = screenName; string socialName = (string)jo["name"]; string location = (string)jo["location"]; string email = ""; string profilePictureUrl = (string)jo["profile_image_url_https"]; App.Instance.User = new User(socialId, name, socialName, email, profilePictureUrl, "Twitter"); App.Instance.userC = new UserC() { UserName = name, Locale = location, FirstName = socialName, PhotoUrl = profilePictureUrl, LinkTwitter = "https://twitter.com/" + screenName, TwitterId = socialId }; }); }
public async static Task <string> GetReviewsAsync(int id) { var dict = new Dictionary <string, string>(); dict.Add("id", id.ToString()); dict.Add("key", "K7gUv8myuMHUFxeNnDjfDQ"); dict.Add("text_only", "true"); var request = new OAuth1Request("GET", new Uri("https://www.goodreads.com/book/show.xml"), dict, AuthorizationService.Instance.CurrentUser); var response = await request.GetResponseAsync(); if (response != null) { var data = response.GetResponseText(); var doc = XDocument.Parse(data); string cdata = doc.Element("GoodreadsResponse").Element("book").Element("reviews_widget").Value; /*Gets the url for the reviews that can be find in a string that contains ' src="<url here>" ' * This is a pretty bad solution, but the web api gave back a html structure ( in CDATA), * which was also badly formatted as it had multiple roots*/ var match = Regex.Match(cdata, "src=\"[^\"]*"); string s = match.Value; //removes the first 5 character ( src=" ) to get the url return(s.Substring(5)); } return(""); }
async void PerformAuth1TestRequests(AuthProvider ap, Account account) { foreach (KeyValuePair <string, string> p in account.Properties) { System.Diagnostics.Debug.WriteLine("Property: Key:" + p.Key + " Value:" + p.Value); } try { foreach (string requestUrl in ap.apiRequests) { OAuth1Request request = new OAuth1Request("GET", new Uri(requestUrl), null, account, false); IResponse response = await request.GetResponseAsync(); ResponseText = response.GetResponseText(); } } catch (Exception ex) { ErrorText = "PerformAuth1TestRequests: Exception:"; for (Exception inner = ex; inner != null; inner = inner.InnerException) { ErrorText += "Message:" + inner.Message + "\n"; } foreach (KeyValuePair <string, string> p in account.Properties) { ErrorText += "Key:" + p.Key + " Value:" + p.Value + "\n"; } } }
private async void btnTwitter_Clicked(object sender, EventArgs e) { //otro codigo var httpClient = new HttpClient(new LoggingHandler(new HttpClientHandler())); var accounts = _services.Accounts; if (accounts.Contains(LoginServices.Twitter)) { var account = _services.getAccount(); var request = new OAuth1Request("GET", new Uri("https://api.twitter.com/1.1/account/verify_credentials.json"), null, account); var response = await request.GetResponseAsync(); var json = response.GetResponseText(); } else { var waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset); var authorizePage = new AuthorizePage(LoginServices.Twitter, this); authorizePage.Disappearing += async(sender2, e2) => { //waitHandle.Set(); await ExtraerInfoTwitter(); }; await Navigation.PushAsync(authorizePage); } }
public async static Task <List <string> > ListShelvesAsync() { var dict = new Dictionary <string, string>(); dict.Add("user_id", AuthorizationService.Instance.UserID.ToString()); var request = new OAuth1Request("GET", new Uri("https://www.goodreads.com/shelf/list.xml"), dict, AuthorizationService.Instance.CurrentUser); var response = await request.GetResponseAsync(); if (response != null) { var data = response.GetResponseText(); var doc = XDocument.Parse(data); var list = new List <string>(); foreach (XElement e in doc.Descendants("user_shelf")) { list.Add(e.Element("name").Value); } return(list); } return(new List <string>()); }
private async Task ExtraerInfoTwitter() { var account = _services.getAccount(); if (account != null) { var request = new OAuth1Request("GET", new Uri("https://api.twitter.com/1.1/account/verify_credentials.json"), null, account); var response = await request.GetResponseAsync(); var json = response.GetResponseText(); Debug.WriteLine(json); usuariosService = new UsuariosService(); var resultado = await usuariosService.PostUsuarioTwitterAsync(json); UsuariosEventosService usuariosEventosService = new UsuariosEventosService(); UsuariosEventos usuariosEventos = new UsuariosEventos(); SesionService sesionService = new SesionService(); var idUsuarios = await sesionService.GetSesionIdUserDbAsync(); usuariosEventos.idEvento = evento.idEventos; usuariosEventos.idUsuario = idUsuarios; var resultadoUE = await usuariosEventosService.setUsuarioEvento(usuariosEventos); await Navigation.PushAsync(new DetalleEventoPage(evento)); } }
private void TwitterAuth(object sender, EventArgs ee) { var auth = new OAuth1Authenticator( Constants.TWITTER_KEY, Constants.TWITTE_SECRET, new Uri(Constants.TWITTE_REQ_TOKEN), new Uri(Constants.TWITTER_AUTH), new Uri(Constants.TWITTER_ACCESS_TOKEN), new Uri(Constants.TWITTE_CALLBACKURL)); auth.AllowCancel = true; StartActivity(auth.GetUI(this)); auth.Completed += async(s, e) => { if (!e.IsAuthenticated) { Toast.MakeText(this, Constants.FAIL_AUTH, ToastLength.Short).Show(); return; } progressDialog = ProgressDialog.Show(this, Constants.WAIT, Constants.CHECKING_INFO, true); var request = new OAuth1Request("GET", new Uri(Constants.TWITTER_REQUESTURL), null, e.Account); var response = await request.GetResponseAsync(); if (response != null) { progressDialog.Hide(); var userJson = response.GetResponseText(); StoringDataIntoCache(userJson); } }; }
async public static Task <TwitterResponse> GetTwitterAccount(Account account) { string credentials_url = "https://api.twitter.com/1.1/account/verify_credentials.json"; var request = new OAuth1Request("GET", new Uri(credentials_url), null, account); TwitterResponse twitterResponse = null; await request.GetResponseAsync().ContinueWith(t => { if (t.IsFaulted) { System.Diagnostics.Debug.WriteLine("Error: " + t.Exception.InnerException.Message); return; } var res = t.Result; var resString = res.GetResponseText(); twitterResponse = JsonConvert.DeserializeObject <TwitterResponse>(resString); var outlet = new Outlet(); outlet.Handle = twitterResponse.screen_name; outlet.Type = Outlet.outlet_type_twitter; outlet.Name = twitterResponse.screen_name; RealmServices.SaveOutlet(outlet); }); return(twitterResponse); }
public async Task <TwitterResponse> GetTwitterProfileAsync(Account account) { var TwitterProfileInfoURL = Xamarin.Forms.Application.Current.Resources["TwitterProfileInfoURL"].ToString(); var requestUrl = new OAuth1Request("GET", new Uri(TwitterProfileInfoURL), null, account); var response = await requestUrl.GetResponseAsync(); return(JsonConvert.DeserializeObject <TwitterResponse>(response.GetResponseText())); }
public async static Task <List <Book> > ListBooksOfShelfAsync(string shelf) { string uri = "https://www.goodreads.com/review/list?id=" + AuthorizationService.Instance.UserID.ToString() + "&v=2&key=K7gUv8myuMHUFxeNnDjfDQ&shelf=" + shelf; var request = new OAuth1Request("GET", new Uri(uri), null, AuthorizationService.Instance.CurrentUser); var response = await request.GetResponseAsync(); if (response != null) { var content = response.GetResponseText(); var doc = XDocument.Parse(content); var books = new List <Book>(); foreach (XElement element in doc.Descendants("book")) { var id = Int32.Parse(element.Element("id").Value); int year; if (!String.IsNullOrWhiteSpace(element.Element("publication_year").Value)) { year = Int32.Parse(element.Element("publication_year").Value); } else { year = -1; } var rating = Double.Parse(element.Element("average_rating").Value); var title = element.Element("title").Value; XElement author = element.Element("authors").Element("author"); var name = author.Element("name").Value; var sImg = element.Element("small_image_url").Value; var img = element.Element("image_url").Value; var book = new Book { ID = id, BookTitle = title, Author = name, Rating = rating, PublicationYear = year, SmallImageURL = sImg, ImageURL = img }; books.Add(book); } return(books); } return(new List <Book>()); }
public void StartAuthorization() { OAuth1Authenticator auth = new OAuth1Authenticator ( consumerKey: "K7gUv8myuMHUFxeNnDjfDQ", consumerSecret: "5Gn7aJAMNYU8L6kcdUiic5debIFqw2m4RqwoQa9ys8", requestTokenUrl: new Uri("https://www.goodreads.com/oauth/request_token"), authorizeUrl: new Uri("https://www.goodreads.com/oauth/authorize"), accessTokenUrl: new Uri("https://www.goodreads.com/oauth/access_token"), callbackUrl: new Uri("custom://scheme.hu") ); auth.AllowCancel = true; auth.Completed += async(sender, eventArgs) => { if (eventArgs.IsAuthenticated) { if (eventArgs.Account != null && eventArgs.Account.Properties != null) { CurrentUser = eventArgs.Account; var request = new OAuth1Request("GET", new Uri("https://www.goodreads.com/api/auth_user"), null, CurrentUser); var response = await request.GetResponseAsync(); if (response != null) { var xmlData = response.GetResponseText(); var doc = XDocument.Parse(xmlData); UserID = Int32.Parse(doc.Element("GoodreadsResponse").Element("user").Attribute("id").Value); } } else { Console.WriteLine("Account properties does not exists"); } } else { Console.WriteLine("Cancelled"); } }; auth.Error += (s, ea) => { Console.WriteLine("Cancelled"); }; DependencyService.Get <IAuthorization>().Authorize(auth); }
// Gets the users Twitter Profile Information using the supplied // Account information public async Task <JObject> GetTwitterProfile(Account account) { // Construct our RequestUrl using our BaseAddress and the Twitter API var RequestUrl = new Uri(String.Format($"{client.BaseAddress}/account/verify_credentials.json")); // Get our profile information using the RequestUrl and the account // information of the user var oRequest = new OAuth1Request("GET", RequestUrl, null, account); var response = await oRequest.GetResponseAsync(); // Return the response object back to the caller return(JObject.Parse(response?.GetResponseText())); }
public async static Task AddNewShelf(string shelfName) { var dict = new Dictionary <string, string>(); dict.Add("user_shelf[name]", shelfName); var request = new OAuth1Request("POST", new Uri("https://www.goodreads.com/user_shelves.xml"), dict, AuthorizationService.Instance.CurrentUser); await request.GetResponseAsync(); }
async void TwitterAuth_CompletedAsync(object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { var request = new OAuth1Request("GET", new System.Uri("http://mobile.twitter.com"), null, e.Account); var response = await request.GetResponseAsync(); var json = response.GetResponseText(); //var twitteruser = JsonConvert.DeserializeObject<TwitterUser>(json); } }
public async static Task AddBookToShelfAsync(int id, string shelf) { var dict = new Dictionary <string, string>(); dict.Add("book_id", id.ToString()); dict.Add("name", shelf); var request = new OAuth1Request("POST", new Uri("https://www.goodreads.com/shelf/add_to_shelf.xml"), dict, AuthorizationService.Instance.CurrentUser); await request.GetResponseAsync(); }
public async static Task <Review> GetUserReviewAsync(int bookId) { var dict = new Dictionary <string, string>(); dict.Add("user_id", AuthorizationService.Instance.UserID.ToString()); dict.Add("book_id", bookId.ToString()); dict.Add("key", "K7gUv8myuMHUFxeNnDjfDQ"); var request = new OAuth1Request("GET", new Uri("https://www.goodreads.com/review/show_by_user_and_book.xml"), dict, AuthorizationService.Instance.CurrentUser); var response = await request.GetResponseAsync(); if (response != null) { var data = response.GetResponseText(); var doc = XDocument.Parse(data); XElement root = doc.Element("GoodreadsResponse"); if (root.Value.Contains("review not found")) { Review r = new Review() { ID = 0, Rating = 0, Comment = "" }; return(r); } XElement review = root.Element("review"); ulong id = UInt64.Parse(review.Element("id").Value); int rating = Int32.Parse(review.Element("rating").Value); string comment = review.Element("body").Value; Review rev = new Review() { ID = id, Rating = rating, Comment = comment }; return(rev); } return(new Review()); }
public async static Task EditReviewAsync(string reviewId, int rating, string comment) { var dict = new Dictionary <string, string>(); dict.Add("review[rating]", rating.ToString()); dict.Add("review[review]", comment.Trim()); string uri = "https://www.goodreads.com/review/" + reviewId + ".xml"; var request = new OAuth1Request("POST", new Uri(uri), dict, AuthorizationService.Instance.CurrentUser); await request.GetResponseAsync(); }
public async static Task AddReviewAsync(string book_id, int rating, string comment) { var dict = new Dictionary <string, string>(); dict.Add("book_id", book_id); dict.Add("review[rating]", rating.ToString()); dict.Add("review[review]", comment); var request = new OAuth1Request("POST", new Uri("https://www.goodreads.com/review.xml"), dict, AuthorizationService.Instance.CurrentUser); await request.GetResponseAsync(); }
// Sends a twitter message using the supplied Account information public async Task <string> TweetMessage(string message, Account account) { // Construct our RequestUrl using our BaseAddress and the Twitter API var RequestUrl = new Uri(String.Format($"{client.BaseAddress}/statuses/update.json")); // Add the Authentication headers that are required for the request var oAuthData = new Dictionary <string, string>(); oAuthData.Add("status", message); oAuthData.Add("trim_user", "1"); // Post the Tweet, using the RequestUrl and oAuthData header information var oRequest = new OAuth1Request("POST", RequestUrl, oAuthData, account); var response = await oRequest.GetResponseAsync(); // Return the response string back to the caller return(response?.GetResponseText()); }
public async Task <TResult> OAuth1Request <TResult>(RequestMethods method, string url, OAuthAccount account, Dictionary <string, string> parameters = null, bool includeMultipart = false) { var stringMethod = Enum.GetName(typeof(RequestMethods), method); Request1 = new OAuth1Request(stringMethod, new Uri(url), parameters, account, includeMultipart); var response = await Request1.GetResponseAsync(); if (response != null) { string resultJson = response.GetResponseText(); var result = JsonConvert.DeserializeObject <TResult>(resultJson); return(result); } return(Activator.CreateInstance <TResult>()); }
async private void twitter_auth_Completed(object sender, AuthenticatorCompletedEventArgs eventArgs) { if (eventArgs.IsAuthenticated) { var request = new OAuth1Request("GET", new Uri("https://api.twitter.com/1.1/account/verify_credentials.json"), null, eventArgs.Account); var response = await request.GetResponseAsync(); var json = response.GetResponseText(); _twitterUser = JsonConvert.DeserializeObject <TwitterUser>(json); UserAccount.SetUserId(_twitterUser); OnLoggedInHandler(); } }
async void TwitterAuth_Completed(object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { Console.WriteLine("login successfull"); var request = new OAuth1Request( "GET", new System.Uri("https://api.twitter.com/1.1/account/verify_credentials.json?screen_name=thulanspartacus&user_id=953234789087236096"), null, e.Account ); var response = await request.GetResponseAsync(); var json = response.GetResponseText(); var twitteruser = JsonConvert.DeserializeObject <TwitterUser>(json); //_descriptionLabel.Text += twitteruser.name; } }
private async void twitter_auth_Completed(object sender, AuthenticatorCompletedEventArgs eventArgs) { if (eventArgs.IsAuthenticated) { Toast.MakeText(this, "Authenticated.!!", ToastLength.Long).Show(); //use the account object and make the desired API call var request = new OAuth1Request( "GET", new Uri("https://api.twitter.com/1.1/account/verify_credentials.json"), null, eventArgs.Account); await request.GetResponseAsync().ContinueWith(t => { var resString = t.Result.GetResponseText(); var data = JsonValue.Parse(resString); // UserData.userData = data; }); } }
async void TwitterAuth_Completed(object sender, AuthenticatorCompletedEventArgs e) { DismissViewController(true, null); if (e.IsAuthenticated) { var request = new OAuth1Request("GET", new Uri("https://api.twitter.com/1.1/account/verify_credentials.json"), null, e.Account); var response = await request.GetResponseAsync(); var json = response.GetResponseText(); var twitterUser = JsonConvert.DeserializeObject <TwitterUser>(json); DismissViewController(true, null); lb1.Text = "Hi: " + twitterUser.name; } DismissViewController(true, null); }
public async Task <TwitterUser> GetUser() { var account = await _accountStore.GetFirst(); var request = new OAuth1Request("GET", new Uri(Constants.TwitterGetUserUrl), //new Dictionary<string, string>() //{ // {"include_entities", "true"}, // {"include_email", "false"} //}, null, account); var response = await request.GetResponseAsync().ConfigureAwait(false); var json = response.GetResponseText(); var jObject = JObject.Parse(json); return(new TwitterUser(jObject)); }
private async void OnTwitterAuthenticationCompletedAsync(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth1Authenticator; if (authenticator != null) { authenticator.Completed -= OnTwitterAuthenticationCompletedAsync; authenticator.Error -= OnTwitterAuthenticationFailed; } if (e.IsAuthenticated) { //now user is authenticated,so lets go and save important keys AccountStore.Create().Save(e.Account, Constants.TwitterAppNameAndorid); var request = new OAuth1Request("GET", new Uri("https://api.twitter.com/1.1/account/verify_credentials.json"), null, e.Account); var response = await request.GetResponseAsync(); if (response != null) { string userJson = response.GetResponseText(); Debug.Print(userJson); Models.TwitterUser twitterUser = JsonConvert.DeserializeObject <Models.TwitterUser>(userJson); //lets update ui with data received from provider UpdateProfileUIWith(twitterUser); } //var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account); //var response = await request.GetResponseAsync(); //if (response != null) //{ //string userJson = response.GetResponseText(); //user = JsonConvert.DeserializeObject<GoogleUserModel>(userJson); ////lets update ui with data received from provider //UpdateProfileUIWith(user); //} } }
async void TwitterAuth_Completed(object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { var request = new OAuth1Request("GET", new Uri("https://api.twitter.com/1.1/account/verify_credentials.json"), null, e.Account); var response = await request.GetResponseAsync(); var json = response.GetResponseText(); var twitterUser = JsonConvert.DeserializeObject <TwitterUser>(json); NameLabel.Text = twitterUser.name; IdLabel.Text = twitterUser.id.ToString(); DescriptionLabel.Text = twitterUser.description; PictureImage.Image = UIImage.LoadFromData(NSData.FromUrl(new NSUrl(twitterUser.profile_image_url_https))); CoverImage.Image = UIImage.LoadFromData(NSData.FromUrl(new NSUrl(twitterUser.profile_banner_url))); } DismissViewController(true, null); }
public async Task <TokenResponse> GetTwitterProfileAsync(Account account) { var TwitterProfileInfoURL = Xamarin.Forms.Application.Current.Resources["TwitterProfileInfoURL"].ToString(); var requestUrl = new OAuth1Request( "GET", new Uri(TwitterProfileInfoURL), null, account); var response = await requestUrl.GetResponseAsync(); var responseTwitter = JsonConvert.DeserializeObject <TwitterResponse>(response.GetResponseText()); var url = Xamarin.Forms.Application.Current.Resources["UrlAPI"].ToString(); var prefix = Xamarin.Forms.Application.Current.Resources["UrlPrefix"].ToString(); var controller = Xamarin.Forms.Application.Current.Resources["UrlUsersController"].ToString(); var apiService = new ApiService(); var token = await apiService.LoginTwitter( url, prefix, $"{controller}/LoginTwitter", responseTwitter); return(token); }
private void TwitterPost(Account twitterAccount, string message, string clientID, string secrete, string link) { var request = new OAuth1Request("GET", new Uri("https://api.twitter.com/1.1/account/verify_credentials.json"), null, twitterAccount); request.GetResponseAsync().ContinueWith(t => { if (t.IsFaulted) { TwitterLoginPost(clientID, secrete, message, link); } else { // 1. Create the service var twitter = new TwitterService { ConsumerKey = clientID, ConsumerSecret = secrete }; twitter.SaveAccount(nn_activity, twitterAccount); // 2. Create an item to share var item = new Item(); item.Text = message; if (link != null) { item.Links.Add(new Uri(link)); } var shareIntent = twitter.GetShareUI(nn_activity, item, result => { // result lets you know if the user shared the item or canceled if(result.Equals(ShareResult.Done)){ nn_activity.RunOnUiThread(()=>{ (nn_activity as HomeScreen).ShowCustomAlterDialogFragment("Success Share Message","Ok",null,"alter.raffledetial.twittersuccess"); }); }else{ nn_activity.RunOnUiThread(()=>{ (nn_activity as HomeScreen).ShowCustomAlterDialogFragment("Failed to Share Message","Ok",null,"alter.raffledetial.twitterfailed"); }); } }); nn_activity.RunOnUiThread(()=>{ nn_activity.StartActivity(shareIntent); }); } }); }
private void TwitterPost(Account twitterAccount, string message, string clientID, string secrete, string link) { var request = new OAuth1Request("GET", new Uri("https://api.twitter.com/1.1/account/verify_credentials.json"), null, twitterAccount); request.GetResponseAsync().ContinueWith(t => { if (t.IsFaulted) { TwitterLoginPost(clientID, secrete, message, link); } else { // 1. Create the service var twitter = new TwitterService { ConsumerKey = clientID, ConsumerSecret = secrete }; twitter.SaveAccount(twitterAccount); // 2. Create an item to share var item = new Item(); item.Text = message; if (!String.IsNullOrEmpty(link) ) { item.Links.Add(new Uri(link)); } // 3. Present the UI on iOS InvokeOnMainThread(() => { UIViewController cur_ViewController=(auth_ViewController==null?c_ViewController:auth_ViewController); var shareController = twitter.GetShareUI(item, result => { new UIAlertView ("Result",result.ToString(), null, "Ok").Show (); c_ViewController.DismissViewController(true,null); }); cur_ViewController.PresentViewController(shareController, true, null); }); } }); }
private void TwitterPost(Account twitterAccount, string message, string clientID, string secrete, string link) { var request = new OAuth1Request("GET", new Uri("https://api.twitter.com/1.1/account/verify_credentials.json"), null, twitterAccount); request.GetResponseAsync().ContinueWith(t => { if (t.IsFaulted) { Console.WriteLine("Error: " + t.Exception.InnerException.Message); TwitterLoginPost(clientID, secrete, message, link); } else { // 1. Create the service var twitter = new TwitterService { ConsumerKey = clientID, ConsumerSecret = secrete }; twitter.SaveAccount(twitterAccount); // 2. Create an item to share var item = new Item(); item.Text = message; if (link != null) { item.Links.Add(new Uri(link)); } // 3. Present the UI on iOS InvokeOnMainThread(() => { var shareController = twitter.GetShareUI(item, result => { UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, null); }); UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(shareController, true, null); }); } }); }
private void TwitterPost(Account twitterAccount, string message, string clientID, string secrete, string link) { var request = new OAuth1Request("GET", new Uri("https://api.twitter.com/1.1/account/verify_credentials.json"), null, twitterAccount); request.GetResponseAsync().ContinueWith(t => { if (t.IsFaulted) { Console.WriteLine("Error: " + t.Exception.InnerException.Message); TwitterLoginPost(clientID, secrete, message, link); } else { // 1. Create the service var twitter = new TwitterService { ConsumerKey = clientID, ConsumerSecret = secrete }; twitter.SaveAccount(Forms.Context, twitterAccount); // 2. Create an item to share var item = new Item(); item.Text = message; if (link != null) { item.Links.Add(new Uri(link)); } // 3. Present the UI Device.BeginInvokeOnMainThread(() => { // 3. Present the UI on iOS var shareIntent = twitter.GetShareUI((Activity)Forms.Context, item, result => { // result lets you know if the user shared the item or canceled }); Forms.Context.StartActivity(shareIntent); }); } }); }