|
AjaxData
jQuery.ajax を使って OpenSocial のデータを操作できます。jQuery.get や jQuery.post, jQuery.getData, jQuery.postData のショートカットも使えます。
jQuery.ajax, jQuery.get, jQuery.post, jQuery.getData, jQuery.postData
jQuery.ajax の datatype="data" は opensocial-0.8 を必要とします。 <ModulePrefs title="opensocial-jquery"> <Require feature="opensocial-0.8" /> </ModulePrefs> プロフィールや友達リストを取得するjQuery.ajax を使って、プロフィールや友達リストを取得できます。このとき url に /people からはじまるパスと dataType に data を指定します。 $.ajax({
url: '/people/@viewer/@friends',
data: {},
dataType: 'data',
success: function(people) {
$.each(people, function(i, person) {
console.info(person.id);
console.info(person.nickname);
});
},
error: function(xhr, status, e) {
console.info(xhr, status, e);
}
});また jQuery.get を使っても同じことができます。 $.get('/people/@viewer/@friends', {}, function(people) {}, 'data');さらに jQuery.getData を使っても同じことができます。 $.getData('/people/@viewer/@friends', {}, function(people) {});詳しくは People を見てください。 アプリケーションのデータを取得するjQuery.ajax を使って、アプリケーションのデータを取得できます。このとき url に /appdata からはじまるパスと dataType に data を指定します。 $.ajax({
url: '/appdata/@viewer/@friends',
data: {},
dataType: 'data',
success: function(data) {
$.each(data, function(userId, data) {
console.info(data.comment.text);
console.info(data.comment.lastModified);
console.info(data.feeling);
console.info(data.footprint);
});
},
error: function(xhr, status, e) {
console.error(xhr, status, e);
}
});また jQuery.get を使っても同じことができます。 $.get('/appdata/@viewer/@friends', {}, function(data) {}, 'data');さらに jQuery.getData を使っても同じことができます。 $.getData('/appdata/@viewer/@friends', {}, function(data) {});詳しくは AppData を見てください。 アプリケーションのデータを保存するjQuery.ajax を使って、アプリケーションのデータを保存できます。このとき url に /appdata からはじまるパスと dataType に data を指定します。 $.ajax({
type: 'post',
url: '/appdata/@viewer/@self',
data: {
comment: { text: 'Say Hello!', lastModified: new Date().getTime() },
feeling: 'well',
footprint: true
},
dataType: 'data',
success: function() {},
error: function(xhr, status, e) {
console.error(xhr, status, e);
}
});また jQuery.post を使っても同じことができます。 $.post('/appdata/@viewer/@self', {
comment: { text: 'Say Hello!', lastModified: new Date().getTime() },
feeling: 'well',
footprint: true
}, function() {}, 'data');さらに jQuery.postData を使っても同じことができます。 $.postData('/appdata/@viewer/@self', {
comment: { text: 'Say Hello!', lastModified: new Date().getTime() },
feeling: 'well',
footprint: true
}, function() {});詳しくは AppData を見てください。 アクティビティを取得するjQuery.ajax を使って、アクティビティを取得できます。このとき url に /activities からはじまるパスと dataType に data を指定します。 $.ajax({
url: '/activities/@viewer/@friends',
data: {},
dataType: 'data',
success: function(activities) {
$.each(activities, function(i, activity) {
console.info(activity.title);
$.each(activity.mediaItems, function(i, mediaItem) {
console.log(mediaItem.mimeType);
console.log(mediaItem.url);
});
});
},
error: function(xhr, status, e) {
console.info(xhr, status, e);
}
});また jQuery.get を使っても同じことができます。 $.get('/activities/@viewer/@friends', {}, function(activities) {}, 'data');さらに jQuery.getData を使っても同じことができます。 $.getData('/activities/@viewer/@friends', {}, function(activities) {});詳しくは Activity を見てください。 アクティビティを保存するjQuery.ajax を使って、アクティビティを保存できます。このとき url に /activities からはじまるパスと dataType に data を指定します。 $.ajax({
type: 'post',
url: '/activities/@viewer/@self',
data: {
title: 'Say Hello!'
mediaItems: [{
mimeType: 'image/gif',
url: 'http://example.com/data.gif'
}]
},
dataType: 'data',
success: function() {},
error: function(xhr, status, e) {
console.error(xhr, status, e);
}
});また jQuery.post を使っても同じことができます。 $.post('/activities/@viewer/@self', { title: 'Say Hello!' }, function() {}, 'data');さらに jQuery.postData を使っても同じことができます。 $.postData('/activities/@viewer/@self', { title: 'Say Hello!' }, function() {});詳しくは Activity を見てください。 メッセージを送信するjQuery.ajax を使って、メッセージを送信できます。このとき url に /messages からはじまるパスと dataType に data を指定します。 $.ajax({
type: 'post',
url: '/messages/@viewer/@outbox',
data: {
recipients: '@owner',
title: 'Say hello!',
body: 'You should be shining!'
},
dataType: 'data',
success: function(data, status) {},
error: function(xhr, status, e) {
console.log('error', xhr, status, e);
}
});また jQuery.post を使っても同じことができます。 $.post('/messages/@viewer/@outbox', {
recipients: '@owner', title: 'Say hello!', body: 'You should be shining!'
}, function() {}, 'data');さらに jQuery.postData を使っても同じことができます。 $.postData ('/messages/@viewer/@outbox', {
recipients: '@owner', title: 'Say hello!', body: 'You should be shining!'
}, function() {});詳しくは Message を見てください。 アルバムリストを取得するjQuery.ajax を使って、アルバムリストを取得できます。このとき url に /albums からはじまるパスと dataType に data を指定します。 $.ajax({
url: '/albums/@viewer/@self',
data: {},
dataType: 'data',
success: function(albums) {
$.each(albums, function(i, album) {
console.info(album.id);
console.info(album.title);
console.info(album.thumbnailUrl);
});
},
error: function(xhr, status, e) {
console.error(xhr, status, e);
}
});また jQuery.get を使っても同じことができます。 $.get('/albums/@viewer/@self', {}, function(albums) {}, 'data');さらに jQuery.getData を使っても同じことができます。 $.getData('/albums/@viewer/@self', {}, function(albums) {});詳しくは Album を見てください。 アルバムの写真リストを取得するjQuery.ajax を使って、アルバムの写真リストを取得できます。このとき url に /mediaitems からはじまるパスと dataType に data を指定します。 $.ajax({
url: '/mediaitems/@viewer/@self/1251149609611',
data: {},
dataType: 'data',
success: function(mediaitems) {
$.each(mediaitems, function(i, mediaitem) {
console.info(mediaitem.id);
console.info(mediaitem.url);
console.info(mediaitem.title);
console.info(mediaitem.thumbnailUrl);
});
},
error: function(xhr, status, e) {
console.error(xhr, status, e);
}
});また jQuery.get を使っても同じことができます。 $.get('/mediaitems/@viewer/@self/1251149609611', {}, function(mediaitems) {}, 'data');さらに jQuery.getData を使っても同じことができます。 $.getData('/mediaitems/@viewer/@self/1251149609611', {}, function(mediaitems) {});詳しくは MediaItem を見てください。 |