Save() public méthode

public Save ( String token, String secret ) : void
token String
secret String
Résultat void
Exemple #1
0
        AuthorizeIfRequested()
        {
            AssertValid();

            switch (m_oTwitterAuthorizationControl.Status)
            {
            case TwitterAuthorizationStatus.HasTwitterAccountAuthorized:

                return(true);

            case TwitterAuthorizationStatus.HasTwitterAccountNotAuthorized:

                TwitterAccessToken.Delete();

                // Continue below.

                break;

            default:

                Debug.Assert(false);
                break;
            }

            // Get a Twitter request token.

            oAuthTwitter oTwitterAuth = new oAuthTwitter(
                HttpNetworkAnalyzerBase.UserAgent,
                HttpNetworkAnalyzerBase.HttpWebRequestTimeoutMs);

            Uri oAuthorizationUri = new Uri(oTwitterAuth.AuthorizationLinkGet());

            String sRequestToken = HttpUtility.ParseQueryString(
                oAuthorizationUri.Query)["oauth_token"];

            Debug.Assert(!String.IsNullOrEmpty(sRequestToken));

            // Open the Twitter authorization page.

            Process.Start(oAuthorizationUri.ToString());

            // Tell the user that the Twitter authorization page has been opened in
            // a browser window, and get the PIN that Twitter provides after
            // authorization is complete.

            TwitterAuthorizingDialog oTwitterAuthorizingDialog =
                new TwitterAuthorizingDialog();

            if (oTwitterAuthorizingDialog.ShowDialog(
                    m_oTwitterAuthorizationControl.ParentForm) != DialogResult.OK)
            {
                return(false);
            }

            // Convert the request token to an access token.

            oTwitterAuth.Token = sRequestToken;

            oTwitterAuth.AccessTokenGet(
                sRequestToken, oTwitterAuthorizingDialog.Pin);

            Debug.Assert(!String.IsNullOrEmpty(oTwitterAuth.Token));
            Debug.Assert(!String.IsNullOrEmpty(oTwitterAuth.TokenSecret));

            // Save the access token.

            TwitterAccessToken oTwitterAccessToken = new TwitterAccessToken();

            oTwitterAccessToken.Save(oTwitterAuth.Token, oTwitterAuth.TokenSecret);

            return(true);
        }
    AuthorizeIfRequested()
    {
        AssertValid();

        switch (m_oTwitterAuthorizationControl.Status)
        {
            case TwitterAuthorizationStatus.NoTwitterAccount:

                // Delete any access token that exists.

                TwitterAccessToken.Delete();
                return (true);

            case TwitterAuthorizationStatus.HasTwitterAccountAuthorized:

                return (true);

            case TwitterAuthorizationStatus.HasTwitterAccountNotAuthorized:

                TwitterAccessToken.Delete();

                // Continue below.

                break;

            default:

                Debug.Assert(false);
                break;
        }

        // Get a Twitter request token.

        oAuthTwitter oTwitterAuth = new oAuthTwitter(
            HttpNetworkAnalyzerBase.UserAgent,
            HttpNetworkAnalyzerBase.HttpWebRequestTimeoutMs);

        Uri oAuthorizationUri = new Uri( oTwitterAuth.AuthorizationLinkGet() );

        String sRequestToken = HttpUtility.ParseQueryString(
            oAuthorizationUri.Query)["oauth_token"];

        Debug.Assert( !String.IsNullOrEmpty(sRequestToken) );

        // Open the Twitter authorization page.

        Process.Start( oAuthorizationUri.ToString() );

        // Tell the user that the Twitter authorization page has been opened in
        // a browser window, and get the PIN that Twitter provides after
        // authorization is complete.

        TwitterAuthorizingDialog oTwitterAuthorizingDialog =
            new TwitterAuthorizingDialog();

        if (oTwitterAuthorizingDialog.ShowDialog(
            m_oTwitterAuthorizationControl.ParentForm) != DialogResult.OK)
        {
            return (false);
        }

        // Convert the request token to an access token.

        oTwitterAuth.Token = sRequestToken;

        oTwitterAuth.AccessTokenGet(
            sRequestToken, oTwitterAuthorizingDialog.Pin);

        Debug.Assert( !String.IsNullOrEmpty(oTwitterAuth.Token) );
        Debug.Assert( !String.IsNullOrEmpty(oTwitterAuth.TokenSecret) );

        // Save the access token.

        TwitterAccessToken oTwitterAccessToken = new TwitterAccessToken();
        oTwitterAccessToken.Save(oTwitterAuth.Token, oTwitterAuth.TokenSecret);

        return (true);
    }