0

Web プログラミングの学習を始めたばかりです (Udacity でクラス CS 253 を受講しています)。

私の質問は、JS と Google アプリ エンジンの統合はどのように機能するのですか? これは Web プログラミングに関する基本的な質問かもしれませんが、この概念を理解する方法についてのガイダンスが本当に必要です。

Twitch Javascript API を Google App Engine に取り込もうとしています。基本的に、ユーザーがTwitch経由でログインでき、情報をデータベースに保存できる小さなWebサイトが欲しいです。TwitchにはJavascript APIしかないため、これがどのように可能かは本当にわかりません。

これは私が持っているスクリプトで、Twitch への接続に完全に機能します (git ページの例から):

<html>
<head>
  <meta charset="utf-8">
  <title>TwitchTV SDK Example App</title>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

  <script src="https://ttv-api.s3.amazonaws.com/twitch.min.js"></script>

  <script>
    window.CLIENT_ID = '';
    $(function() {
      // Initialize. If we are already logged in, there is no
      // need for the connect button
      Twitch.init({clientId: CLIENT_ID}, function(error, status) {
        if (status.authenticated) {
          // we're logged in :)
          $('.status input').val('Logged in! Allowed scope: ' + status.scope);
          // Show the data for logged-in users
          $('.authenticated').removeClass('hidden');
        } else {
          $('.status input').val('Not Logged in! Better connect with Twitch!');
          // Show the twitch connect button
          $('.authenticate').removeClass('hidden');
        }
      });


      $('.twitch-connect').click(function() {
        Twitch.login({
          scope: ['user_read', 'channel_read']
        });
      })

      $('#logout button').click(function() {
        Twitch.logout();

        // Reload page and reset url hash. You shouldn't
        // need to do this.
        window.location = window.location.pathname
      })

      $('#get-name button').click(function() {
        Twitch.api({method: 'user'}, function(error, user) {
          $('#get-name input').val(user.display_name);
        });
      })

      $('#get-stream-key button').click(function() {
        Twitch.api({method: 'channel'}, function(error, channel) {
          $('#get-stream-key input').val(channel.stream_key);
        });
      })

    });
  </script>

  <style type="text/css">
  .hidden {
    display: none;
  }
  </style>
</head>
<body>
  <h1>TwitchTV SDK Example App</h1>
    <div class="status">
      Status: <input readonly="readonly" size="60" val="Unknown"/>
    </div>
    <div class="authenticate hidden">
      <img src="http://ttv-api.s3.amazonaws.com/assets/connect_dark.png" class="twitch-connect" href="#" />
    </div>

    <h2 class="authenticated hidden">Authenticated</h2>
    <div class="authenticated hidden">
      <div id="logout">
        <button>Log Out</button>
      </div>

      <div id="get-name">
        <button>Get TwitchTV Name</button>
        <input readonly="readonly" size="50" value="Unknown"/>
      </div>

      <div id="get-stream-key">
        <button>Get TwitchTV Stream Key</button>
        <input readonly="readonly" size="50" value="Unknown"/>
      </div>

    </div>
</body>
</html>

このクライアント側 JavaScript と Google App Engine の間でデータを通信するにはどうすればよいですか? ありがとう!

4

1 に答える 1

1

非常に幅広い質問です。しかし、一般的に、あなたのケースに関して:

  • App Engine アプリケーションで受信側 (ハンドラ) を設定する必要があります。クライアント側の JavaScript からのリクエストを処理します ( Hello, world の例)
  • 次に、実際にデータをサーバーに送信する必要があります。jQueryを使っているようです。Hello, worldの例で見たサーバーを呼び出すには、次のように記述します$.get('/', function(data) {console.log(data);})。これにより、サーバーが呼び出され、サーバーから取得したメッセージがコンソールに出力されます。
于 2014-12-30T10:52:28.610 に答える