Exemplo n.º 1
0
        static void Main( string[] args )
        {
            try {
                System.Net.ServicePointManager.Expect100Continue = false;

                // リクエストトークンを取得
                OAuthProvider provider = new OAuthProvider( APIKey.AccessToken, APIKey.Authorize, APIKey.ReqestToken );
                OAuthConsumer consumer = new OAuthConsumer( OAuth.APIKey.ConsumerKey, OAuth.APIKey.ConsumerSecret );
                string authorizeURL = provider.RetrieveRequestToken( ref consumer );

                //ブラウザからPIN確認
                System.Diagnostics.Process.Start( authorizeURL );
                Console.Write( "PIN:" );
                string pin = Console.ReadLine();

                // アクセストークンを取得
                provider.RetrieveAccessToken( ref consumer, pin );

                Console.WriteLine( "public const string Token = \"" + consumer.Token + "\";" );
                Console.WriteLine( "public const string TokenSecret = \"" + consumer.TokenSecret + "\";" );

                //デスクトップ\oauth_token.txtに保存
                File.WriteAllText( Environment.GetFolderPath( Environment.SpecialFolder.Desktop ) + @"\cacoo_oauth_token.txt",
                    consumer.Token + ", " + consumer.TokenSecret );
            }
            catch ( Exception ex ) {
                Console.WriteLine( ex.Message );
            }
            finally {
                Console.Write( "Press enter : " );
                Console.ReadLine();
            }
        }
Exemplo n.º 2
0
        static void Main( string[] args )
        {
            try {
                System.Net.ServicePointManager.Expect100Continue = false;

                OAuthConsumer consumer = new OAuthConsumer( APIKey.ConsumerKey, APIKey.ConsumerSecret );
                consumer.SetTokenWithSecret( APIKey.Token, APIKey.TokenSecret );

                OAuthProvider provider = new OAuthProvider();

                string result = "";

                result = provider.RetrieveRequest( "https://cacoo.com/api/v1/account.xml", consumer );
                Console.WriteLine( "--- アカウント情報取得 ---" );
                Console.WriteLine( result );
                Console.WriteLine( "" );

                result = provider.RetrieveRequest( "https://cacoo.com/api/v1/users/kaorun55.xml", consumer );
                Console.WriteLine( "--- ユーザー情報取得 ---" );
                Console.WriteLine( result );
                Console.WriteLine( "" );

                result = provider.RetrieveRequest( "http://cacoo.com/api/v1/diagrams.xml", consumer );
                Console.WriteLine( "--- 図の一覧取得 ---" );
                Console.WriteLine( result );
                Console.WriteLine( "" );

                result = provider.RetrieveRequest( "http://cacoo.com/api/v1/diagrams/cTedXHIB8T1x1QJS.xml", consumer );
                Console.WriteLine( "--- 図の情報取得 ---" );
                Console.WriteLine( result );
                Console.WriteLine( "" );

                // バイナリの返し方を考える
                //result = provider.RetrieveRequest( "http://cacoo.com/api/v1/diagrams/cTedXHIB8T1x1QJS.png", consumer );
                //Console.WriteLine( "--- 画像取得 ---" );
                //Console.WriteLine( result );
                //Console.WriteLine( "" );
            }
            catch ( Exception ex ) {
                Console.WriteLine( ex.Message );
            }
            finally {
                Console.Write( "Press enter : " );
                Console.ReadLine();
            }
        }