PHP function to read friends-only LiveJournal posts through RSS · Заметки

The code is pretty self-explanatory. The only know-how is the combination of the options which works with LJ.
The global variables $digest_username and $digest_password should be set to your LiveJournal username and password, respectievely.
The $url should like like: http://www.livejournal.com/users/tl1/data/rss/?auth=digest

UPD: (The Russian version):
PHP-код для чтения закрытых постов в ЖЖ через RSS
Ищу способ снова читать ЖЖ и массу других блогов в одном централизованном приложении. Естественно, это возможно только через RSS. Как оказалось, у ЖЖ есть возможность читать защищённые записи через RSS, но не всё так просто, т.к. отдавалка RSS требует определённых уговоров и, например, Tiny Tiny RSS не справляется с получением защищённых фидов. В интернетах также нет работающего в настоящий момент примера кода, поэтому я решил запостить результат своих изысканий. Код тривиальный, фишка только в наборе параметров cURL.
$digest_username, $digest_password - глобальные переменные с вашим логином и паролем в ЖЖ.
URL защищённого фида: http://www.livejournal.com/users/tl1/data/rss/?auth=digest
(Замените tl1 на произвольный %USERNAME% ЖЖ.)
Вы получите RSS с записями пользователя, включая приватные, которые он открыл вам.

·· [Continuing] ··

function get($url) {
    global $digest_username, $digest_password;
    if (!$digest_username)
      return file_get_contents($url);
    $auth = "$digest_username:$digest_password";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
    curl_setopt($ch, CURLOPT_USERPWD, $auth);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $res = curl_exec($ch);
    curl_close($ch);
    return $res;
}

UPD: Some discussion can be found here: http://tl1.livejournal.com/351315.html




Comments:

No Comments for this post yet...

Leave a comment:

Your email address will not be displayed on this site.
Your URL will not be displayed on this site. Comments containing URL's of non-personal pages may be removed.
Confirmation Code:
Human Confirmation Code (Captcha)

HTML tags and "<", ">" symbols are not allowed. Links will not be converted to hyperlinks. Any commercials are removed and reported as abuse.

Archives

                                                                                                                                                                                                                                                                   


© Sergey A. Galin, 1998-2021 sageshome.net/blog/