| Новости | FAQ | Авторы | Документация | В действии | Библиотека |
| Инструменты | Полезные ссылки | Хостинги | Скачать | Примеры | Форум |
Creator 12.05.2008 22:27
Для Livejournal flat API есть такой код:###############################################################################################
# Класс синхронизации с LJ
#
@CLASS
lj
###############################################################################################
# Инициализация базы
#
@init[lj_user;lj_password][]
$ljUser[$lj_user]
# hashed password!
$ljPass[$lj_password]
$ljAgent[Mozilla/4.0 ^[LJBot from http://creator.bcsoft.org/^; ljbot@bcsoft.org^]]
###############################################################################################
# Парсинг ответа LJ flat API
#
@ljParseResponse[resp][pairs;propname;propvalue]
$pairs[^resp.split[^#0A;v]]
$result[^hash::create[]]
^pairs.menu{
^if(def $propname){
$propvalue[$pairs.piece]
^if(def $propvalue){
$result.[$propname][$propvalue]
$propname[]
}
}{
$propname[$pairs.piece]
}
}
###############################################################################################
# Авторизация challenge/response
#
@ljAuth[][f;resp]
^try{
$f[^file::load[text;http://www.livejournal.com/interface/flat;
$.method[POST]
$.timeout(60)
$.charset[utf-8]
$.form[
$.mode[getchallenge]
]
$.headers[
$.User-Agent[$ljAgent]
]
]]
$result[^ljParseResponse[$f.text]]
$resp[^math:md5[${result.challenge}^ljPass.lower[]]]
$result.response[^resp.lower[]]
}{
$exception.handled(1)
}
###############################################################################################
# Постинг нового сообщения
#
@ljPost[d;subj;text;id][authHash;id]
$authHash[^ljAuth[]]
^if($authHash.success eq "OK"){
^try{
$f[^file::load[text;http://www.livejournal.com/interface/flat;
$.method[POST]
$.timeout(60)
$.charset[utf-8]
$.form[
^if(def $id && $id > 0){
$.mode[editevent]
$.itemid[$id]
}{
$.mode[postevent]
}
$.user[$ljUser]
$.auth_method[challenge]
$.auth_challenge[$authHash.challenge]
$.auth_response[$authHash.response]
$.lineendings[unix]
$.subject[$subj]
$.event[$text]
$.year[$d.year]
$.mon[$d.month]
$.day[$d.day]
$.hour[$d.hour]
$.min[$d.minute]
]
$.headers[
$.User-Agent[$ljAgent]
]
]]
$result[^ljParseResponse[$f.text]]
^if(def $result.id){
# already in ID
}{
$id[^result.url.match[http://.*.livejournal.com/(\d+)\.html]]
^if(def $id.1){
$result.id[$id.1]
}{
$result.id[0]
}
}
}{
# $result[$authHash]
$exception.handled(1)
}
}{
$result[$authHash]
}