?

Log in

No account? Create an account
Accessing Comments via PHP - LiveJournal Client Discussions [entries|archive|friends|userinfo]
LiveJournal Client Discussions

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Accessing Comments via PHP [Dec. 10th, 2005|08:26 pm]
LiveJournal Client Discussions

lj_clients

[bgarmisa]
Howdy,

I'm working on my website, which grabs the XML feed of my journal and displays the posts there... I'm adding some AJAX into the mix (as you can see by clicking "drink the melanade" at http://www.bengarmisa.com/blog ) also. I'd love to be able to use AJAX to display comments underneath each post when someone clicks "see who drank the melanade." The problem with this is that the only way I can see to export comments is by using the comment exporting tool (using a php f_open call similar to "http://www.livejournal.com/export_comments.bml?get=comment_body&startid=maxid+1...")...

This poses a multitude of problems... The first being that I believe you need to login in order to view comments... I can't figure out a way to get PHP to send a cookie *to* livejournal.com... I've figured out how to use sessiongenerate to generate a session ID, but I don't know if there's any way to have PHP send that session ID back to the server...

The second problem that arises here is that the comment exporting tool only displays "jitemid" to reference which journal entry any given comment is linked to... The XML feed, however, only shows the UNIQUE journal entry id (a five digit number--the same number you see in every entry's permlink). I can't figure out any way to figure out how the jitemid and unique journal entry id correstpond, so even if I could get PHP to send the correct sessionid back to livejournal.com, the comment data I got back would be pretty much useless...

any ideas?
linkReply

Comments:
From: snej
2005-12-16 01:47 am (UTC)
To send a cookie: You'll probably need to move up to a more powerful library for sending the GET -- something like libcurl. Then use its API to add a cookie to the request.

The entry ID thing is pretty screwy. Back when I was doing some work with the LJ protocol, I was able to work out some of this stuff. The post info from the getevents command includes an "itemid" and an "anum". The number that shows up in the item's permalink is 256*itemid+anum. It sounds like you have the itemids (from the LJ protocol) and the permalinks (from the feed) and need to correlate them without having the 'anum's. You could probably do this by dividing the permalink numbers by 256, since IIRC the anums are always less than 256.
(Reply) (Thread)
[User Picture]From: njyoder
2005-12-16 06:34 am (UTC)
That is correct, I just checked and verified that. In the process of doing that, I discovered a bug. The journal entry count on the user info page is incorrect. When you delete a post, it decreases the count by 3. It appears that it doesn't drop below the actual comment count.
(Reply) (Parent) (Thread)
[User Picture]From: njyoder
2005-12-16 06:38 am (UTC)
Actually, I'm not sure about not dropping below the comment count, but I do know it can't go negative.
(Reply) (Parent) (Thread)
[User Picture]From: ibneko
2005-12-16 02:31 am (UTC)
Cookie eh... Hmmm, perl's LWP useragent + whatever module it was that handles cookies? I don't remember it off the top of my head - it's been too long since I've messed with it.
(Reply) (Thread)