Exemple #1
0
        //
        // Used to authorize an HTTP request going to TwitPic
        //
        public static void AuthorizeTwitPic(OAuthConfig config, HttpWebRequest wc, string oauthToken, string oauthTokenSecret)
        {
            var headers = new Dictionary <string, string>()
            {
                { "oauth_consumer_key", config.ConsumerKey },
                { "oauth_nonce", MakeNonce() },
                { "oauth_signature_method", "HMAC-SHA1" },
                { "oauth_timestamp", MakeTimestamp() },
                { "oauth_token", oauthToken },
                { "oauth_version", "1.0" },
                //{ "realm", "http://api.twitter.com" }
            };
            string signurl = "http://api.twitter.com/1/account/verify_credentials.xml";
            // The signature is not done against the *actual* url, it is done against the verify_credentials.json one
            string signature           = MakeSignature("GET", signurl, headers);
            string compositeSigningKey = MakeSigningKey(config.ConsumerSecret, oauthTokenSecret);
            string oauth_signature     = MakeOAuthSignature(compositeSigningKey, signature);

            headers.Add("oauth_signature", OAuth.PercentEncode(oauth_signature));

            Util.Log("Headers: " + HeadersToOAuth(headers));
            wc.Headers.Add("X-Verify-Credentials-Authorization", HeadersToOAuth(headers));
            wc.Headers.Add("X-Auth-Service-Provider", signurl);
        }
Exemple #2
0
        // Invoked after the user has authorized us
        //
        // TODO: this should return the stream error for invalid passwords instead of
        // just true/false.
        public bool AcquireAccessToken()
        {
            var headers = new Dictionary <string, string> ()
            {
                { "oauth_consumer_key", config.ConsumerKey },
                { "oauth_nonce", MakeNonce() },
                { "oauth_signature_method", "HMAC-SHA1" },
                { "oauth_timestamp", MakeTimestamp() },
                { "oauth_version", "1.0" }
            };
            var content = "";

            if (xAuthUsername == null)
            {
                headers.Add("oauth_token", AuthorizationToken);
                headers.Add("oauth_verifier", AuthorizationVerifier);
            }
            else
            {
                headers.Add("x_auth_username", OAuth.PercentEncode(xAuthUsername));
                headers.Add("x_auth_password", OAuth.PercentEncode(xAuthPassword));
                headers.Add("x_auth_mode", "client_auth");
                content = String.Format("x_auth_mode=client_auth&x_auth_password={0}&x_auth_username={1}", OAuth.PercentEncode(xAuthPassword), OAuth.PercentEncode(xAuthUsername));
            }

            string signature           = MakeSignature("POST", config.AccessTokenUrl, headers);
            string compositeSigningKey = MakeSigningKey(config.ConsumerSecret, RequestTokenSecret);
            string oauth_signature     = MakeOAuthSignature(compositeSigningKey, signature);

            var wc = new WebClient();

            headers.Add("oauth_signature", OAuth.PercentEncode(oauth_signature));
            if (xAuthUsername != null)
            {
                headers.Remove("x_auth_username");
                headers.Remove("x_auth_password");
                headers.Remove("x_auth_mode");
            }
            wc.Headers [HttpRequestHeader.Authorization] = HeadersToOAuth(headers);

            try {
                var result = HttpUtility.ParseQueryString(wc.UploadString(new Uri(config.AccessTokenUrl), content));

                if (result ["oauth_token"] != null)
                {
                    AccessToken       = result ["oauth_token"];
                    AccessTokenSecret = result ["oauth_token_secret"];
                    AccessScreenname  = result ["screen_name"];
                    AccessId          = Int64.Parse(result ["user_id"]);

                    return(true);
                }
            } catch (WebException e) {
                var x = e.Response.GetResponseStream();
                var j = new System.IO.StreamReader(x);
                Console.WriteLine(j.ReadToEnd());
                Console.WriteLine(e);
                // fallthrough for errors
            }
            return(false);
        }
Exemple #3
0
 static string MakeSigningKey(string consumerSecret, string oauthTokenSecret)
 {
     return(OAuth.PercentEncode(consumerSecret) + "&" + (oauthTokenSecret != null ? OAuth.PercentEncode(oauthTokenSecret) : ""));
 }
Exemple #4
0
        public void EditList(string originalName, ListDefinition list)
        {
            var editor = new DialogViewController(null, true);
            var name   = new EntryElement(Locale.GetText("Name"), null, list.Name);

            name.Changed += delegate {
                editor.NavigationItem.RightBarButtonItem.Enabled = !String.IsNullOrEmpty(name.Value);
            };
            var description = new EntryElement(Locale.GetText("Description"), Locale.GetText("optional"), list.Description);
            var privacy     = new RootElement(Locale.GetText("Privacy"), new RadioGroup("key", (int)list.Privacy))
            {
                new Section()
                {
                    new RadioElement(Locale.GetText("Public")),
                    new RadioElement(Locale.GetText("Private"))
                }
            };

            editor.NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem(UIBarButtonSystemItem.Cancel, delegate {
                DeactivateController(true);
            }), false);

            editor.NavigationItem.SetRightBarButtonItem(new UIBarButtonItem(UIBarButtonSystemItem.Save, delegate {
                string url = String.Format("http://api.twitter.com/1/{0}/lists{1}.json?name={2}&mode={3}{4}",
                                           TwitterAccount.CurrentAccount.Username,
                                           originalName == null ? "" : "/" + originalName,
                                           OAuth.PercentEncode(name.Value),
                                           privacy.RadioSelected == 0 ? "public" : "private",
                                           description.Value == null ? "" : "&description=" + OAuth.PercentEncode(description.Value));
                TwitterAccount.CurrentAccount.Post(url, "");
            }), false);

            editor.NavigationItem.RightBarButtonItem.Enabled = !String.IsNullOrEmpty(name.Value);
            editor.Root = new RootElement(Locale.GetText("New List"))
            {
                new Section()
                {
                    name, description, privacy
                }
            };
            ActivateController(editor);
        }
Exemple #5
0
        void Post()
        {
            var content = new StringBuilder();
            var account = TwitterAccount.CurrentAccount;

            if (directRecipient == null)
            {
                content.AppendFormat("status={0}", OAuth.PercentEncode(composerView.Text));
                AppendLocation(content);
                if (InReplyTo != 0)
                {
                    content.AppendFormat("&in_reply_to_status_id={0}", InReplyTo);
                }
                account.Post("http://twitter.com/statuses/update.json", content.ToString());
            }
            else
            {
                content.AppendFormat("text={0}&user={1}", OAuth.PercentEncode(composerView.Text), OAuth.PercentEncode(directRecipient));
                AppendLocation(content);
                account.Post("http://twitter.com/direct_messages/new.json", content.ToString());
            }
            CloseComposer(this, EventArgs.Empty);
        }
        void CreateUI()
        {
            System.Threading.Thread.Sleep(2000);
            if (spinner != null)
            {
                spinner.RemoveFromSuperview();
                spinner = null;
            }

            var profileRect      = new RectangleF(PadX, 0, View.Bounds.Width - PadX, 100);
            var shortProfileView = new ShortProfileView(profileRect, user.Id, false);

            shortProfileView.PictureTapped += delegate { PictureViewer.Load(this, user.Id); };
            shortProfileView.UrlTapped     += delegate { WebViewController.OpenUrl(this, user.Url); };

            var main = new Section(shortProfileView);

            if (!String.IsNullOrEmpty(user.Description))
            {
                main.Add(new StyledMultilineElement(user.Description)
                {
                    Lines         = 0,
                    LineBreakMode = UILineBreakMode.WordWrap,
                    Font          = UIFont.SystemFontOfSize(14),
                });
            }
            ;

            var tweetsUrl    = String.Format("http://api.twitter.com/1/statuses/user_timeline.json?skip_user=true&id={0}", user.Id);
            var favoritesUrl = String.Format("http://api.twitter.com/1/favorites.json?id={0}", user.Id);
            var followersUrl = String.Format("http://api.twitter.com/1/statuses/followers.json?id={0}", user.Id);
            var friendsUrl   = String.Format("http://api.twitter.com/1/statuses/friends.json?id={0}", user.Id);

#if false
            followButton = new StyledStringElement(FollowText, ToggleFollow)
            {
                Alignment = UITextAlignment.Center,
                TextColor = UIColor.FromRGB(0x32, 0x4f, 0x85)
            };
#endif
            var sfollow = new Section()
            {
                new ActivityElement()
            };

            Root = new RootElement(user.Screenname)
            {
                main,
                new Section()
                {
                    TimelineRootElement.MakeTimeline(user.Screenname, Locale.Format("{0:#,#} tweets", user.StatusesCount), tweetsUrl, user),
                    TimelineRootElement.MakeFavorites(user.Screenname, Locale.Format("{0:#,#} favorites", user.FavCount), favoritesUrl, null),
                    new UserRootElement(user, Locale.Format("{0:#,#} friends", user.FriendsCount), friendsUrl),
                    new UserRootElement(user, Locale.Format("{0:#,#} followers", user.FollowersCount), followersUrl),
                },
                sfollow,
            };
            var created = user.CreatedAt;
            if (created.HasValue)
            {
                Root.Add(new Section(null, Locale.Format("Joined on {0}", created.Value.ToLongDateString())));
            }

            string url = String.Format("http://api.twitter.com/1/friendships/show.json?target_id={0}&source_screen_name={1}",
                                       user.Id,
                                       OAuth.PercentEncode(TwitterAccount.CurrentAccount.Username));
            TwitterAccount.CurrentAccount.Download(url, res => {
                TableView.BeginUpdates();
                Root.Remove(sfollow);
                if (res != null)
                {
                    ParseFollow(res);
                }

                TableView.EndUpdates();
            });
        }
Exemple #7
0
 public SearchViewController(string search) :
     base(search, "http://search.twitter.com/search.json?q=" + OAuth.PercentEncode(search), "rpp=", 50, "since_id=", "page=", null)
 {
     //View.AddSubview (bottomBar);
 }