|
People
It is possible to obtain a profile and a friends list. It's also possible to specify profile items and the criteria for filtering, sorting, and paging.
jQuery.ajax, jQuery.get, jQuery.getData en, ja
opensocial-0.8 is required for datatype="data" in jQuery.ajax <ModulePrefs title="opensocial-jquery"> <Require feature="opensocial-0.8" /> </ModulePrefs> Obtain a ProfileIt is possible to obtain a VIEWER profile using jQuery.ajax $.ajax({
url: '/people/@viewer/@self',
data: {},
dataType: 'data',
success: function(people) {
var person = people[0];
console.info(person.id);
console.info(person.nickname);
console.info(person.name.unstructured);
},
error: function(xhr, status, e) {
console.info(xhr, status, e);
}
});This can also be done using jQuery.get $.get('/people/@viewer/@self', {}, function(people) {}, 'data');The same can be done using jQuery.getData $.getData('/people/@viewer/@self', {}, function(people) {});It is possible to obtain an OWNER profile using jQuery.ajax $.ajax({
url: '/people/@owner/@self',
data: {},
dataType: 'data',
success: function(people) {
var person = people[0];
console.info(person.id);
console.info(person.nickname);
console.info(person.name.unstructured);
},
error: function(xhr, status, e) {
console.info(xhr, status, e);
}
});This can also be done using jQuery.get $.get('/people/@owner/@self', {}, function(people) {}, 'data');The same can be done using jQuery.getData $.getData('/people/@owner/@self', {}, function(people) {});Obtaining a Friends ListIt is possible to obtain a VIEWER's friends list using jQuery.ajax $.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);
}
});This can also be done using jQuery.get $.get('/people/@viewer/@friends', {}, function(people) {}, 'data');The same can be done using jQuery.getData $.getData('/people/@viewer/@friends', {}, function(people) {});It is possible to obtain an OWNER's friends list using jQuery.ajax $.ajax({
url: '/people/@owner/@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);
}
});This can also be done using jQuery.get $.get('/people/@owner/@friends', {}, function(people) {}, 'data');The same can be done using jQuery.getData $.getData('/people/@owner/@friends', {}, function(people) {});Specify Profile Itemsfields parameters can be used to specify Profile Items. Profile items can be specified by comma-delimiting. $.ajax({
url: '/people/@viewer/@self',
data: { fields: 'profileUrl,addresses' },
dataType: 'data',
success: function(people) {
var person = people[0];
console.info(person.profileUrl);
console.info(person.addresses[0].country);
console.info(person.addresses[0].region);
},
error: function(xhr, status, e) {
console.info(xhr, status, e);
}
});Moreover, the fields parameters can also define the URL $.ajax({
url: '/people/@viewer/@self?fields=profileUrl,addresses',
data: {},
dataType: 'data',
success: function(people) {},
error: function(xhr, status, e) {}
});Specifying Data ItemsappData parameters can be used to specify application data items. Data items can be specified by comma-delimiting. $.ajax({
url: '/people/@viewer/@self',
data: { appData: 'comment,feeling' },
dataType: 'data',
success: function(people) {
var person = people[0];
console.info(person.appData.comment);
console.info(person.appData.feeling);
},
error: function(xhr, status, e) {
console.error(xhr, status, e);
}
});Moreover, the appData parameters can also define the URL $.ajax({
url: '/people/@viewer/@self?appData=comment,feeling',
data: {},
dataType: 'data',
success: function(people) {},
error: function(xhr, status, e) {}
});Furthermore, if the appData parameter data items are abbreviated, all data items can be displayed $.ajax({
url: '/people/@viewer/@self?appData',
data: {},
dataType: 'data',
success: function(people) {
var person = people[0];
console.info(person.appData.comment);
console.info(person.appData.feeling);
console.info(person.appData.footprint);
},
error: function(xhr, status, e) {}
});Specifying Filter CriteriaFilter criteria can be specified using the URL path. Either @all or @app can be specified. The choice is @all when abbreviated.
$.ajax({
url: '/people/@viewer/@friends/@app',
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);
}
});Filter criteria can be specified using filterBy parameters. Either all, hasApp, topFriends, or isFriendsWith can be specified. The choice is all when abbreviated.
$.ajax({
url: '/people/@viewer/@friends',
data: { filterBy: 'hasApp' },
dataType: 'data',
success: function(people) {},
error: function(xhr, status, e) {}
});Moreover, filterBy parameters can also be used to specify the URL $.ajax({
url: '/people/@viewer/@friends?filterBy=hasApp',
data: {},
dataType: 'data',
success: function(people) {},
error: function(xhr, status, e) {}
});Specifying Sort CriteriaSort criteria can be specified using sortBy parameters. Either topFriends or name can be specified. The choice is topFriends when abbreviated.
$.ajax({
url: '/people/@viewer/@friends',
data: { sortBy: 'name' },
dataType: 'data',
success: function(people) {},
error: function(xhr, status, e) {}
});Moreover, sortBy parameters can also be used to specify the URL $.ajax({
url: '/people/@viewer/@friends?sortBy=name',
data: {},
dataType: 'data',
success: function(people) {},
error: function(xhr, status, e) {}
});Specifying Paging CriteriaThe paging criteria can be specified by using startIndex and count parameters. startIndex can be used with location to specify the position and with count to specify the number obtained. startIndex uses "0" to indicate item number 1. When abbreviated, numbers are used through to 20 items. $.ajax({
url: '/people/@viewer/@friends',
data: { startIndex: 0, count: 10 },
dataType: 'data',
success: function(people) {},
error: function(xhr, status, e) {}
});Furthermore, the startIndex and count parameters can also define the URL $.ajax({
url: '/people/@viewer/@friends?startIndex=0&count=10',
data: {},
dataType: 'data',
success: function(people) {},
error: function(xhr, status, e) {}
});Moreover, it is possible to retrieve location, the number of items per page, and the total number of items from a friends list. $.ajax({
url: '/people/@viewer/@friends',
data: {},
dataType: 'data',
success: function(people) {
console.info(people.startIndex);
console.info(people.itemsPerPage);
console.info(people.totalResults);
},
error: function(xhr, status, e) {}
});HTML UnescapeProfiles are HTML unescapes with jQuery.ajax, jQuery.get, and jQuery.getData |
jQuery(function($) {
});こんなコードで VIEWER の性別を取得すると問題無く取得出来るのですが、@self を @friends に変えると、mixi、goo ホームともに友人の性別についてとれた試しがありません。これは、コンテナ側が出力似対応していないってことなんでしょうかね?
ちなみに、友人の中にはプロフィールの性別を「全体に公開」にしている人もおり、公開範囲の問題だけでは切り分けられないかと思います。
Mixi の振る舞いは分かりませんが、gooホームは明確に条件が開示されています。
「全体に公開」にしている友達は、同じガジェットをインストールしていますでしょうか。「同じガジェットを使っていて」かつ「全体に公開」が条件になると思います。
詳しくは、gooホームの公式ドキュメントを見てみてください。
gooホームガジェット > パーミッションモデル http://developer.home.goo.ne.jp/
また、その背景はgooホームの担当者の方のブログで解説しています。
Tender Surrender » OpenSocial?のパーミッションモデル http://devlog.agektmr.com/ja/archives/512
opensocial-jquery の実装としては @self か @friends のときと、処理を区別していませんので、コンテナの振る舞いによるものだと思います。
大分変わったと思うので、上記についてはまた試してみます。
mixi で自分のプロフィールを取るとき、
$.getData('/people/@viewer/@self?fields=age,gender,boodType,addresses', {}, function(people) {});
などとしてみましたが、血液型はとれないようですね。
そもそも血液型は、
var boodType = viewer.getField(mixi.PersonField?.BloodType?);
という感じで標準の opensocial.Person.Field の項目ではないので仕方がないのかもしれませんが。当面は req.newFetchPersonReques と二段構えでやるしかなさそうですね。
フィードバックありがとうございます。
opensocial-jquery は Person.Field が opensocial 準拠かどうか検査していませんので mixi のフィールドも取得できるつもりでいました。
console.log(mixi.PersonField.BloodType) や alert(mixi.PersonField.BloodType) で mixi.PersonField.BloodType の値を調べます。
値が "bloodType" だとすると、次のコードで血液型がとれませんでしょうか? 頂いたコメントの boodType は bloodType のタイプミスでしょうか?
$.getData('/people/@viewer/@self?fields=bloodType', {}, function(people) {});ここにコピペするときに手がすべったか、元々 typo していたかもしれません。後ほどリトライしてみます。ただ、http://developer.mixi.co.jp/news/2009051401 にある方法でもなんかうまく取れなかったので、typo だったかもですね・・・
mixiアプリ開発において、非常に便利に使わせていただいております。 ひとつ質問なのですが、viewerやownerではなく、任意のidを指定してプロフィール情報を取得することは出来ないのでしょうか?
mixi platform で試してはいませんが、仕組み上は @viewer や @owner の変わりに id を指定すればよいはずです。
/people/{id}/@self
ご回答ありがとうございます。 上記でやってみたのですが、エラーが帰ってきてしまいます。 mixi platformでは出来ないということでしょうか。
度々すみません。mixiはパーミッションモデルというのがあって、アプリをインストールしていないユーザーのプロフィールは取得できないようです。インストールしているユーザー情報は上記のやり方で取得することができました。お騒がせしてすみませんでした。
ものすごい遅レスですがmixiアプリで、bloodTypeで血液無事とれました。
mixi.PersonField?.BloodType?はopensocial準拠ではなさそうですが、fieldsで指定するとちゃんとmixi.PersonField?.BloodType?がとれるのはopensocial-jquery内でそういう風に対処をされているからなのでしょうか?
OpenSocial? JavaScript? API の中身は、REST/RPC API を呼び出しています。OpenSocial? JavaScript? API の定数は、REST/RPC API のフィールドを定義している(一部例外はありますが)に過ぎません。ですので、REST/RPC API で "bloodType" というフィールドがあれば、それを指定できるというわけです。