コード例 #1
0
        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
                };
            });
        }
コード例 #2
0
        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 { }
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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";
                }
            }
        }
コード例 #5
0
        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));
            }
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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);
                }
            };
        }
コード例 #8
0
ファイル: Client.cs プロジェクト: RosaGeri95/Bookshelf
        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("");
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
ファイル: Client.cs プロジェクト: RosaGeri95/Bookshelf
        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>());
        }
コード例 #11
0
        public async Task <Tuple <string, CMPShareError> > SendTweetAsync(Dictionary <string, string> parametersDictionary,
                                                                          byte[] imageBytesArray)
        {
            if ((parametersDictionary == null) || (parametersDictionary.Count == 0))
            {
                throw (new ArgumentNullException());
            }

            string mediaIdString = string.Empty;

            if ((imageBytesArray != null) && (imageBytesArray.Length > 0))
            {
                var uploadResultInfo = await UploadMediaAsync(imageBytesArray);

                mediaIdString = ExtractUploadedMediaId(uploadResultInfo);
            }

            if (string.IsNullOrEmpty(mediaIdString) == false)
            {
                parametersDictionary.Add(KMediaIdsKeyString, mediaIdString);
            }

            var graphRequest = new OAuth1Request(KHttpMethodPOSTString, new Uri(KStatusUpdateURLString),
                                                 parametersDictionary, _authenticatedAccount,
                                                 !(string.IsNullOrEmpty(mediaIdString) == true));

            var graphResponse = await PerformGraphAsync(graphRequest);

            return(graphResponse);
        }
コード例 #12
0
        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()));
        }
コード例 #13
0
ファイル: Client.cs プロジェクト: RosaGeri95/Bookshelf
        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>());
        }
コード例 #14
0
        public async Task <Tuple <string, CMPShareError> > GetDirectMessagesAsync(Dictionary <string, string>
                                                                                  parametersDictionary = null)
        {
            var graphRequest = new OAuth1Request(KHttpMethodGETString, new Uri(KRetrieveDirectMessagesURLString),
                                                 parametersDictionary, _authenticatedAccount);
            var graphResponse = await PerformGraphAsync(graphRequest);

            return(graphResponse);
        }
コード例 #15
0
        private async Task <Tuple <string, CMPShareError> > GetTweetsListAsync(string urlString,
                                                                               Dictionary <string, string>
                                                                               parametersDictionary)
        {
            var graphRequest = new OAuth1Request(KHttpMethodGETString, new Uri(urlString), parametersDictionary,
                                                 _authenticatedAccount);
            var graphResponse = await PerformGraphAsync(graphRequest);

            return(graphResponse);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
ファイル: Client.cs プロジェクト: RosaGeri95/Bookshelf
        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();
        }
        // 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()));
        }
コード例 #19
0
        private async Task <Tuple <string, CMPShareError> > UploadMediaAsync(byte[] imageBytesArray)
        {
            var parametersDictionary = new Dictionary <string, string>();

            parametersDictionary.Add(KMediaDataKeyString, Convert.ToBase64String(imageBytesArray));

            var graphRequest = new OAuth1Request(KHttpMethodPOSTString, new Uri(KUploadMediaURLString),
                                                 parametersDictionary, _authenticatedAccount, true);

            var graphResponse = await PerformGraphAsync(graphRequest);

            return(graphResponse);
        }
コード例 #20
0
ファイル: MainActivity.cs プロジェクト: CrisSG91/Prueba-login
        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);
            }
        }
コード例 #21
0
ファイル: Client.cs プロジェクト: RosaGeri95/Bookshelf
        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();
        }
コード例 #22
0
        public async Task <Tuple <string, CMPShareError> > LookupTweetsAsync(Dictionary <string, string>
                                                                             parametersDictionary)
        {
            if ((parametersDictionary == null) || (parametersDictionary.Count == 0))
            {
                throw (new ArgumentNullException());
            }

            var graphRequest = new OAuth1Request(KHttpMethodGETString, new Uri(KLookupTweetURLString), parametersDictionary,
                                                 _authenticatedAccount);
            var graphResponse = await PerformGraphAsync(graphRequest);

            return(graphResponse);
        }
コード例 #23
0
ファイル: Client.cs プロジェクト: RosaGeri95/Bookshelf
        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());
        }
コード例 #24
0
ファイル: Client.cs プロジェクト: RosaGeri95/Bookshelf
        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();
        }
コード例 #25
0
ファイル: Client.cs プロジェクト: RosaGeri95/Bookshelf
        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();
        }
コード例 #26
0
        // 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());
        }
コード例 #27
0
        public async Task <Tuple <string, CMPShareError> > DestroyTweetAsync(string tweetIdString,
                                                                             Dictionary <string, string>
                                                                             parametersDictionary = null)
        {
            if (string.IsNullOrEmpty(tweetIdString) == true)
            {
                throw (new ArgumentNullException());
            }

            var urlString    = string.Format(KDestroyTweetURLString, tweetIdString);
            var graphRequest = new OAuth1Request(KHttpMethodPOSTString, new Uri(urlString), parametersDictionary,
                                                 _authenticatedAccount);
            var graphResponse = await PerformGraphAsync(graphRequest);

            return(graphResponse);
        }
コード例 #28
0
        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>());
        }
コード例 #29
0
        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;
            }
        }
コード例 #30
0
        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();
            }
        }
コード例 #31
0
        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);
                            });
                    }
                });
        }
コード例 #32
0
ファイル: SocialShareIOS.cs プロジェクト: MADMUC/TAP5050
        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);
                            });
                    }
                });
        }
コード例 #33
0
ファイル: SocialShareAndroid.cs プロジェクト: MADMUC/TAP5050
        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);
                        });
                    }
                });
        }
コード例 #34
0
        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);
                            });
                    }
                });
        }