0

Flex (FLex Builder 3.0) は初めてで、基本的に HTTPS 経由で Freshbooks API (www.freshbooks.com) に対して認証する単純なアプリケーションを作成しています。他に何も送信せずに。

これが私がこれまでに持っているものです:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
    <![CDATA[           

        import mx.collections.ArrayCollection;
        import mx.rpc.events.ResultEvent;   
        import mx.utils.Base64Encoder;  

        private function authAndSend(service:HTTPService):void
        {
            var encoder:Base64Encoder = new Base64Encoder();
            encoder.insertNewLines = false; 
            encoder.encode("<freshbooks auth token>:X"); 
           //for some reason, freshbooks says that the authentication token 
           //is the username, and the password could just be a dummy value.

            service.headers = {Authorization:"Basic " + encoder.toString()};                                                               
            service.send();
        }           

        private function freshBooksHandler(event:ResultEvent):void{
            txtArea1.text = event.result.toString();
        }

    ]]>
</mx:Script>

<mx:HTTPService id="freshBooksService" url="https://myaccount.freshbooks.com/api/2.1/xml-in"
    result="freshBooksHandler(event)" resultFormat="xml">       
</mx:HTTPService>

<mx:Button x="59" y="48" label="Button" click="authAndSend(freshBooksService)"/>
<mx:TextArea x="59" y="78" width="401" height="242" id="txtArea1"/>

</mx:Application>

問題は、ボタンをクリックすると、FreshBooks サービスへのユーザー名とパスワードを要求するポップアップがブラウザーに表示されることです。

ユーザー名 (freshbooks によって提供される認証トークン) が、ブラウザーではなく Flex 自体からサーバーに送信されるようにコーディングするにはどうすればよいですか? 私の期待される結果は、ブラウザからのポップアップがなく、freshbooks サーバーが返すものはすべてテキスト領域 (txtArea1) に表示されることです。

注: 認証トークンをブラウザーのポップアップに入力すると、アプリケーションは出力をテキスト領域に正しく表示できます。

ありがとう。

4

2 に答える 2

1

将来的に始めようとしている人を助けるために、ここに例があります:

        // SETUP before any transactions with the web service
        private function setup():void {
            freshCom.setRemoteCredentials(authToken, "x");
        }
        // Fetches a the list of categories from the FreshBooks server
        private function getCategories():void {
            var categoryRequest:XML = <request method='category.list' />;
            freshCom.send(categoryRequest);
        }
        private function handleResult(event:ResultEvent):void {
            // insert breakpoint here to view result
        }   
    ]]>
</mx:Script>
<mx:HTTPService id="freshCom"  url="{serviceURL}" result="handleResult(event)" method="POST" contentType="application/xml" />

于 2010-02-09T14:41:28.680 に答える
0

思い出すと、提供された資格情報が失敗した場合、ブラウザー認証ウィンドウが表示されます。

FreshBook API ドキュメントから:

アカウントの API アクセスを有効にすると、一意の認証トークンが付与されます。API リクエストを行うたびに、基本的な HTTP 認証を使用してこのトークンを提示する必要があります。

使用する認証トークンは、ユーザー名とは異なる必要があります。それは...ですか?

于 2009-11-23T16:50:43.593 に答える