My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
AjaxOAuth  
jQuery.ajax のリクエストに署名できます。jQuery.get や jQuery.post などのショートカットでもリクエストに署名できます。
jQuery.ajax, jQuery.get, jQuery.post, jQuery.getJSON, jQuery.getScript, jQuery.getFeed, jQuery.oauth
Updated Sep 4, 2009 by nakajim...@gmail.com

jQuery.ajax の oauth と jQuery.oauth は opensocial-0.8 と oauthpopup を必要とします。

<Require feature="opensocial-0.8" />
<Require feature="oauthpopup" />

リクエストに署名して、外部ホストからデータを取得する

jQuery.ajax を使って、リクエストに署名して、外部ホストからデータを取得できます。このとき oauth に signed を指定します。

  $.ajax({
    url: 'http://example.com/data.json',
    dataType: 'json',
    oauth: 'signed',
    success: function(data, status) {
      console.log(data, status);
    },
    error: function(xhr, status, e) {
      console.info(xhr, status, e);
    }
  });

jQuery.get を使っても同じことができます。このとき url に続けて signed を指定します。

  $.get('http://example.com/data.json signed', function(data, status) {}, 'json');

jQuery.getJSON でもリクエストに署名できます。

  $.getJSON('http://example.com/data.json signed', function(data, status) {});

jQuery.getScript でもリクエストに署名できます。

  $.getScript('http://example.com/data.js signed', function(data, status) {});

jQuery.getFeed でもリクエストに署名できます。

  $.getFeed('http://example.com/data.atom signed', function(data, status) {});

リクエストに署名して、外部ホストにデータを送信する

jQuery.ajax を使って、リクエストに署名して、外部ホストにデータを送信できます。このとき oauth に signed を指定します。

  $.ajax({
    type: 'post',
    url: 'http://example.com/data.json',
    data: { comment: 'Say Hello!' },
    dataType: 'json',
    oauth: 'signed',
    success: function(data, status) {
      console.log(data, status);
    },
    error: function(xhr, status, e) {
      console.info(xhr, status, e);
    }
  });

jQuery.post を使っても同じことができます。このとき url に続けて signed を指定します。

  $.post('http://example.com/data.json signed', { comment: 'Say Hello!' },
    function(data, status) {}, 'json');

OAuth リクエストで、外部ホストからデータを取得する

jQuery.ajax を使って、リクエストを OAuth 認証して、外部ホストからデータを取得できます。

  $.ajax({
    url: 'http://friendfeed-api.com/v2/feed/nakajiman',
    dataType: 'json',
    oauth: 'friendfeed',
    success: function(data, status) {
      console.info(data, status);
    },
    error: function(xhr, status, e) {
      console.error(xhr, status, e);
    }
  });

このとき oauth に OAuth/Service@name を指定します。

<OAuth>
<Service name="friendfeed">
<Request url="https://friendfeed.com/account/oauth/request_token" param_location="uri-query"/>
<Authorization url="https://friendfeed.com/account/oauth/authorize"/>
<Access url="https://friendfeed.com/account/oauth/access_token" param_location="uri-query"/>
</Service>
</OAuth>

jQuery.get を使っても同じことができます。このとき url に続けて OAuth/Service@name を指定します。

  $.get('http://friendfeed-api.com/v2/feed/nakajiman friendfeed', function(data, status) {}, 'json');

jQuery.getJSON、jQuery.getScript、jQuery.getFeed も同じです。

OAuth リクエストで、外部ホストにデータを送信する

jQuery.ajax を使って、リクエストを OAuth 認証して、外部ホストにデータを送信できます。このとき oauth に OAuth/Service@name を指定します。

  $.ajax({
    type: 'post',
    url: 'http://friendfeed-api.com/v2/entry',
    data: { body: 'Say Hello!' },
    dataType: 'json',
    oauth: 'friendfeed',
    success: function(data, status) {
      console.info(data, status);
    },
    error: function(xhr, status, e) {
      console.error(xhr, status, e);
    }
  });

jQuery.post を使っても同じことができます。このとき url に続けて OAuth/Service@name を指定します。

  $.post('http://friendfeed-api.com/v2/entry friendfeed', { body: 'Say Hello!' },
    function(data, status) {}, 'json');

OAuth リクエストを認証する

jQuery.ajax は OAuth リクエストの認証を必要とするとき、エラーイベントをコールバックします。このとき status は oauth を表します。

  $.ajax({
    type: 'post',
    url: 'http://friendfeed-api.com/v2/entry',
    data: { body: 'Say Hello!' },
    dataType: 'json',
    oauth: 'friendfeed',
    success: function(data, status) {},
    error: function(xhr, status, e) {
      if (status == 'oauth') 
        $('<a href="#signin"/>')
          .text('Sign in with FriendFeed')
          .click(function() {
            $.oauth('friendfeed');
            return false;
          })
          .minimessage();      
    }
  });

続けて jQuery.oauth を使って OAuth リクエストを認証できます。このとき、指定した OAuth/Service@name の認証ページをポップアップウィンドウで開きます。

$.oauth('friendfeed');

また、コールバック関数を指定して、ポップアップウィンドウの閉じるイベントをハンドリングできます。

$.oauth('friendfeed', function() {});

さらに window.open のオプションを指定して、ポップアップウィンドウの外観をカスタマイズできます。

$.oauth('friendfeed', { width: 600, height: 800 }, function() {});

具体的な使い方は The example using OAuth Proxy that post to FriendFeed on gooHome を見てください。

関連リンク

Comment by matsumot...@nissin.co.jp, Aug 2, 2010

hnh


Sign in to add a comment
Powered by Google Project Hosting