コード例 #1
0
ファイル: TwitterApi.cs プロジェクト: yhtsnda/oauth-dot-net
        /// <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));
            }
        }
コード例 #2
0
ファイル: TwitterApi.cs プロジェクト: rpmcpp/oauth-dot-net
        /// <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));
            }
        }