示例#1
0
        public Status UpdateStatus(string status)
        {
            if (status == null)
            {
                throw new ArgumentNullException("status");
            }

            if (string.IsNullOrEmpty(status))
            {
                throw new ArgumentException(
                          "status must not be empty",
                          "status");
            }

            if (status.Length > 140)
            {
                throw new ArgumentException(
                          "status must not be more than 140 characters",
                          "status");
            }

            OAuthResource resource = this.ExecuteRequest(
                TwitterApi.ServiceDefinition,
                new NameValueCollection
            {
                { "status", status }
            },
                "http://twitter.com/statuses/update.xml", "POST");

            return(Status.Deserialize(resource.GetResponseStream()));
        }
示例#2
0
        /// <summary>
        /// Verifies the user credentials and fetches extended user information
        /// for the current user.
        /// </summary>
        /// <param name="user">(Out) extended user information</param>
        /// <param name="options">API options</param>
        /// <returns>
        /// <para>
        /// Returns <c>true</c> and sets <paramref name="user"/> to a
        /// representation of the requesting user if authentication was
        /// successful.
        /// </para>
        /// <para>
        /// Returns <c>false</c> and sets <paramref name="user"/> to null
        /// if authentication was not successful.
        /// </para>
        /// </returns>
        public bool VerifyCredentials(out ExtendedUser user)
        {
            OAuthResource resource = this.ExecuteRequest(
                TwitterApi.ServiceDefinition,
                null,
                "http://twitter.com/account/verify_credentials.xml", "GET");

            switch (resource.StatusCode)
            {
            case HttpStatusCode.Unauthorized:
                user = null;
                return(false);

            case HttpStatusCode.OK:
                user = ExtendedUser.Deserialize(resource.GetResponseStream());
                return(true);

            default:
                throw new InvalidOperationException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              "Unexpected response from Twitter account/verify_credentials.xml: {0}",
                              resource.StatusCode));
            }
        }
示例#3
0
        /// <summary>
        /// Retrieves the 20 most recent statuses posted from the authenticated
        /// user.
        /// </summary>
        /// <param name="options">API options</param>
        /// <returns>List of statuses</returns>
        public ReadOnlyCollection <Status> UserTimeline()
        {
            OAuthResource resource = this.ExecuteRequest(
                TwitterApi.ServiceDefinition,
                null,
                "http://twitter.com/statuses/user_timeline.xml", "GET");

            return(new ReadOnlyCollection <Status>(
                       new ListSerializationHelper().DeserializeStatusList(
                           resource.GetResponseStream())));
        }