Open DhirajBelure opened 6 years ago
I implemented only fetching ability. How to get 30 posts of lifejournalNameToFetch:
$liveJournalClient = new Client($YourLivejournalUserName, $YourLivejournalPassword);
$postDtoList = $liveJournalClient->fetchRecentPosts('lifejournalNameToFetch', 30, $anotherOptions);
$anotherOptions can be empty, but if u want to get next 30 posts, u need to set data from which u need to start searching :
$anotherOptions['beforedate'] = $lastPostDto->createdDate;
**my code*** require('src/LiveJournal/Client.php'); use LiveJournal;// getting warning
var_dump(file_exists("src/LiveJournal/Client.php"));//boolean(true); my path is right
$params = array( 'userName' => '',//username of login livejournal 'passwordHexed' => '' //password of login livejournal );
$liveJournalClient = new Client($params['userName'],$params['passwordHexed']);// getting error on this line. print_r($liveJournalClient);exit();
$postDtoList = $liveJournalClient->fetchRecentPosts('lifejournalNameToFetch', 30, $anotherOptions);
getting error on my page . I have include client.php the for client class and I m working on localhost server.Please. check below error
Warning: The use statement with non-compound name 'LiveJournal' has no effect in /media/medusa/Backup/htdocs/livejournalmaster/livejournalsample.php on line 10
Fatal error: Uncaught Error: Class 'Client' not found in /media/medusa/Backup/htdocs/livejournalmaster/livejournalsample.php:30 Stack trace: #0 {main} thrown in /media/medusa/Backup/htdocs/livejournalmaster/livejournalsample.php on line 30
***Client.php code*
<?php /**
use XML_RPC2_Client;
/**
LiveJournal api client */ class Client { /**
/**
/**
/**
/**
/**
/**
/**
/**
/**
@throws \Exception */ public function __construct($userName, $passwordPlain, $server = null) { $this->userName = $userName; $this->passwordHexed = $this->md5hex($passwordPlain); // clear plain password unset($passwordPlain);
if ($server === null) { $server = self::XML_RPC_SERVER; }
$rpcUrl = $server . self::XML_RPC_PATH;
$this->client = XML_RPC2_Client::create('http://' . $rpcUrl, array('prefix' => self::PREFIX)); $this->clientHttps = XML_RPC2_Client::create('https://' . $rpcUrl, array('prefix' => self::PREFIX));
$challenge = $this->fetchChallenge();
$loginOptions = array( 'username' => $userName, 'clientversion' => 'PHP/livejournal-php-sdk', 'auth_challenge' => $challenge['challenge'], 'auth_response' => $challenge['response'], 'auth_method' => 'challenge' );
$userInfo = $this->client->login($loginOptions); if (!isset($userInfo['username']) || $userInfo['username'] !== $userName) { throw new \Exception('Something goes wrong on login'); } }
/**
@return Post|null */ public function fetchPost($id) { $challenge = $this->fetchChallenge();
$value = array( 'username' => $this->userName, 'auth_method' => 'challenge', 'auth_challenge' => $challenge['challenge'], 'auth_response' => $challenge['response'], 'selecttype' => 'one', 'itemid' => $id );
$eventList = $this->client->getevents($value);
$post = null; if (count($eventList['events']) !== 0) { $post = PostHelper::bindPost($eventList['events'][0]); }
return $post; }
/**
@return Post[] */ public function fetchRecentPosts($journalName = null, $number = self::DEFAULT_POSTS_TO_FETCH, array $anotherOptions = []) { if ($number > self::MAX_POSTS_TO_FETCH) { $number = self::MAX_POSTS_TO_FETCH; }
$challenge = $this->fetchChallenge();
$value = array( 'username' => $this->userName, 'auth_method' => 'challenge', 'auth_challenge' => $challenge['challenge'], 'auth_response' => $challenge['response'], 'selecttype' => 'lastn', 'howmany' => $number, 'prefersubject' => false, 'noprops' => false, 'ver' => 1, 'lineendings' => 'unix', 'notags' => false, ); $value = array_merge($value, $anotherOptions);
if ($journalName) { $value['usejournal'] = $journalName; }
$arData = $this->client->getevents($value);
$postListGroupedById = array(); foreach ($arData['events'] as $event) { $post = PostHelper::bindPost($event); $postListGroupedById[$post->id] = $post; }
return $postListGroupedById; }
/**
@return array */ private function fetchChallenge() { //get challenge for authentication $challengeRaw = $this->clientHttps->getchallenge(array());
$challenge = array( 'challenge' => $challengeRaw['challenge'], 'response' => $this->md5hex( $challengeRaw['challenge'] . $this->passwordHexed ) );
return $challenge; }
/**
@return string md5-hashed hecadecimal representation */ private function md5hex($string) { $md5 = md5($string, true); $hex = ''; for ($nC = 0, $md5Max = strlen($md5); $nC < $md5Max; $nC++) { $hex .= str_pad(dechex(ord($md5[$nC])), 2, '0', STR_PAD_LEFT); }
return $hex; } } ?>
u need to install my library throw composer - https://getcomposer.org/
require('src/LiveJournal/Client.php');
- is not enough
the path of client should be for your code:
$liveJournalClient = new \LiveJournal\Client($params['userName'],$params['passwordHexed']);
*composer.json***** { "name": "konstantin-kuklin/livejournal-php-sdk", "license": "MIT", "type": "library", "description": "The \"LiveJournal\" PHP SDK", "keywords": ["php", "library", "sdk", "livejournal", "lj"], "homepage": "https://github.com/KonstantinKuklin/livejournal-php-sdk", "authors": [ { "name": "Konstantin Kuklin", "email": "konstantin.kuklin@gmail.com" } ], "autoload": { "psr-4": { "LiveJournal\": "src/LiveJournal/" } }, "require": { "pear/xml_rpc2": "dev-trunk", "pear/http_request2": "dev-trunk" } }
above json file i have downloaded .zip package.
Please, give the example of fetch and post record/data from livejournal.