Each version of PHT contains full PhpDoc, don't miss it when you search something, it's really useful.
On the site you will find some pieces of code to help you to start with PHT.
In order to use PHT you need PHP5 (recommanded >= 5.1.2) and cURL extension enabled. If you use old PHP5 (<5.1.2) you need PECL hash >= 1.1
To start developping a CHPP application with PHT you need your oauth consumer key and your oauth consumer secret. Be careful to never give or display your consumer secret !
If you don't have those informations, check your CHPP application page on Hattrick or ask to become a certified CHPP developper.
All examples of code are available from the left menu. If you have questions use comments at bottom of each page, contact form, Hattrick forum or even htmail.
Comments (Post yours)
By Samurai-BR the 20-05-2008
I will try here and when possible return on feedback.
Congrats, on advance.
[=
By destor77 the 23-05-2008
excellent work, I hope more examples (Session, statistics, etc.) to migrate my application to this tool.
By Peaso the 26-05-2008
Thank you!
By destor77 the 26-05-2008
By arash the 24-06-2009
By portugal10 the 07-02-2010
By OR the 12-03-2010
Is it possible to use this to find out how many minutes a player played in a match?
Thanks,
OR
By teles the 12-03-2010 teles Hattrick team
Look at HTMatch and HTEvent classes.
By david the 17-04-2010
By teles the 17-04-2010 teles Hattrick team
By Adriano Moutinho the 08-11-2010
I found some minor mistakes on the code examples. missing and missing ; on line 21 of second example.
Anyway, thanks for the development!
By teles the 08-11-2010 teles Hattrick team
By HiseaSaw the 15-11-2010 HiseaSaw Hattrick team
Are these examples up-to-date?
After login in HT I'm getting this error: oauth_problem=parameter_rejected&oauth_problem_advice=When%20obtaining%20a%20request%20token%2C%20you%20must%20not%20supply%20the%20oauth_token%20parameter
By teles the 15-11-2010 teles Hattrick team
Error you got is strange, can you send me your piece of code?
By HiseaSaw the 15-11-2010 HiseaSaw Hattrick team
I'm getting the error just after typing my credentials at Hattrick page (https://chpp.hattrick.org/oauth/authorize.aspx?oauth_token=[TOKEN]).
Thank you again.
By HiseaSaw the 15-11-2010 HiseaSaw Hattrick team
By teles the 15-11-2010 teles Hattrick team
Nice it works for you :)
By fcheitenried the 16-11-2010
The Authorization works. But how is the code for an automatically login. I always get this error:
oauth_problem=token_rejected&oauth_problem_advice=Supply%20a%20correct%20token
When i get the autorization ther ist an token in the url and an security token. But how goes the automaticaly login.
pls help
thx a lot.
By teles the 16-11-2010 teles Hattrick team
Next time the user comes, you can set back this tokens to PHT and request xml.
It's the third piece of code of this page: http://pht.htloto.org/documentation/connection.html
In this example, tokens are set in $userToken and $userTokenSecret
By fcheitenried the 17-11-2010
But now i want a "directly" link. I got the Tokens from last login.
When i only put the code of the 3rd part it does not work.
thx for ur help.
By teles the 17-11-2010 teles Hattrick team
You just request xml files with these tokens set in PHT
There is no direct link to authenticate user if you have his access token, access is already granted. (if token was not revoke by user on hattrick website)
If it's doesn't help you, I didn't understood your problem, so you will have to explain it differently :)
By Orbix the 21-11-2010
There is an error in function getHatStats() :
return ($this->getMidfieldRating()
instead of
return ($this->getMiedfieldRating()
Besides, when I call this line $match->getFirstHalfTime()
I have this error : Undefined class constant 'SERVER_URL' (line 10245)
thanks
By teles the 21-11-2010 teles Hattrick team
Will be fixed in next version, I do my best to publish it tomorrow
By teles the 22-11-2010 teles Hattrick team
By alessandro the 24-11-2010 alessandro Hattrick team
Tanks
Alessandro
By teles the 24-11-2010 teles Hattrick team
$HT->getWorldDetails()->getLeagueById(5)->getTrainingDate();
with "5" the id of the league you want
You can also get it by requesting with getLeagueByCountryId() and a country id, or getLeagueByName() with an english name, getLeague() with a number according number of leagues returned in xml (get number with getTotalLeague())
By alessandro the 24-11-2010
i was arrived at this (poor poor english) reading the hattrick api documentation but i get the wrong way using getleaguebyid('4'), but i saw in your PHT.php the class HTWorldLeague it's not possible use this?
If is possible to contact you i'll be very happy.
Thanks
By teles the 26-11-2010 teles Hattrick team
By alessandro the 26-11-2010
like u said, but i found in the your lib file (PHT.php) the class HTWorldLeague that seems to have trainingdate function .
Alessandro
By alessandro the 02-12-2010
it's me again, i'm upgrade to last versione and i'm trying
to use getLastMatch() function in this way:
$HT = $_SESSION['HT']
$player = $HT->getPlayer('296383769')
echo $player->getLastMatch()
but i receive a fatal error
Call to a member function hasChildNodes() on a non-object in PHT.php on line 9478
Thanks
Alessandro
By teles the 02-12-2010 teles Hattrick team
By Riccardo the 22-12-2010
By alessandro the 20-01-2011
http://www.modalitaprovvisoria.it/triplete/information.php
Thanks a lot
Alessandro
By teles the 22-01-2011 teles Hattrick team
By alessandro the 24-01-2011
http://www.modalitaprovvisoria.it/triplete/banner.gif
Thanks
Alessandro
By alessandro1977 the 30-01-2011
but i can't get my opponent ID
Thank
Alessandro1977
By Alessandro1977 the 30-01-2011
Thank
Alessandro
By teles the 05-02-2011 teles Hattrick team
You can do it like this:
for($i=1; $i<=$list->getMatchNumber(); $i++)
{
$list->getMatch($i)->getId();
//get others match info here
}
By mogito the 15-02-2011 mogito Hattrick team
J'ai une petite erreur sur ma page de callback :
"Fatal error: main() [function.main]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "CHPPConnection" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in mypage.php on line 20"
Une idée ?
By mogito the 15-02-2011
By teles the 19-02-2011 teles Hattrick team
Le fichier PHT.php doit être inclus avant de récupérer l'objet en session, car si l'objet n'est pas connu par l'interpréteur avant qu'il soit chargé de la session, il ne peut pas être chargé correctement, d'où l'erreur :)
By me9mill the 28-02-2011 me9mill Hattrick team
By Saxbar the 15-03-2011
Je ne comprends pas pourquoi le script suivant (inclu dans une class avec des fonctions) ne retourne rien... même pas une erreur...
$this->HT = $_SESSION['HT'];
$this->arenamystats = $this->HT->getMyArenaStats();
$arenamystats->matchesnumber = $this->arenamystats->getMatchesNumber();
J'ai essayé de placer des arguments dans getMyArenaStats(); comme la syntaxe le permet mais rien...
Merci du coup de main ;)
By teles the 17-03-2011 teles Hattrick team
Merci pour la remontée !
By Saxbar the 18-03-2011
mixed $tomorrowWheaterId = null (line 5612)
By teles the 19-03-2011 teles Hattrick team
By Saxbar the 21-03-2011
HTRegion::getName() retourne l'ID de région. Le soucis se situe ligne 5639 ;) j'ai corrigé chez moi mais je te le dis pour la 2.6
J'en profite pour te dire merci car ton boulot est formidable pour nous qui nous appuyons totalement dessus.
By teles the 23-03-2011 teles Hattrick team
By chew the 05-04-2011
https://chpp.hattrick.org/oauth/authorize.aspx?oauth_token=
So it gives me error.. I have put consumerkey and consumersecret correctly..Why is there this problem? :(
By teles the 06-04-2011 teles Hattrick team
By chew the 06-04-2011
And I have discovered that the problem was that curl that hasn't the support for https.. So I have tryied in a hosting with curl and support https and it works!
Thanks for all :)
By chew the 07-04-2011
I see the third piece of code for connection and it's ok.. but i think that to save and reuse data, I have to link them to the user id..
But How can I recover the user id of the user connected in hattrick? Is there a (chpp)link to recover this info or some function in PHT? Or is use of cookies needed?
Thanks :)
By teles the 07-04-2011 teles Hattrick team
But, if you have no self auth system you won't be able to reuse the token (you have to know which user is the visitor, and without own authentication you can't know visitors then reuse token on future visits. You can use cookie but it's not a safe way)
And you can come when you want, don't leave :)
By chew the 07-04-2011
So have I to create a login on my site...? I thought that there was a way to take parameters of the connection/session of the user to the site of hattrick.. (I have seen some external site that shows status of the user on hattrick..if he's connected or not to hattrick.. but I don't know if it works..)
By Mark the 08-04-2011
PHP Notice: Undefined variable: oauth_token_secret in /srv/http/roba/psiutil/lib/PHT/PHT.php on line 194
why?
By teles the 08-04-2011 teles Hattrick team
@Mark: Does oauth process works? After which function call do you get this notices?
By Mark the 09-04-2011
By chew the 09-04-2011
@Mark: I don't know if your problem is similar to my old problem .. (read my message of 06-04-2011.. maybe is that the problem.. ) :)
By Mark the 09-04-2011
I try the script in a php-cli, how can I solve?
By Saxbar the 09-04-2011
Je viens de tomber là dessus (PHT 2.6) :
Fatal error: Call to a member function getAttribute() on a non-object in /class/PHT.php on line 13320
Si cela provient bien de la PHT, merci de me donner la correction car ca me bloque.
Merci d'avance
Saxbar
By Saxbar the 09-04-2011
Si tu pouvais regarder la fonction get433Experience(),
je pense qu'il y a une coquille dans le code (343 au lieu de 433), elle ne retourne rien.
Merci ;)
Saxbar
By teles the 10-04-2011 teles Hattrick team
By Saxbar the 11-04-2011
encore merci :)
By Saxbar the 19-04-2011
Pour la 2.8, class HTLeagueTeam, getPositionChange(), coquilles sur les lignes 7298 à 7302.
@+ Christophe
By Saxbar the 19-04-2011
Je ne comprends pas, getPositionChange() ne retourne rien.
By teles the 20-04-2011 teles Hattrick team
$this->hasPostionChange = $this->getXml()->getElementsByTagName('PositionChange')->length > 0;
By Saxbar the 21-04-2011
By Saxbar the 21-04-2011
By Saxbar the 22-04-2011
By teles the 22-04-2011 teles Hattrick team
By Saxbar the 22-04-2011
By teles the 22-04-2011 teles Hattrick team
http://www.hattrick.org/Forum/Overview.aspx?v=0&f=765917
By Reelax the 07-05-2011
Can someone tell me how to perform a connection to HT for our OWN team ? So if we already know our login and our secret password, what code should we use ?
I mean if I want to create a website presenting my own team.
Thanks
By teles the 07-05-2011 teles Hattrick team
By eraser the 10-05-2011
How could i use the code from the last box? Where do i get the right token?
Thanks
By teles the 11-05-2011 teles Hattrick team
By josh the 17-05-2011
maybe a noob question but where do i get those consumerKey and consumerSecret?
Must i request them in hattrick via registering an app or how do i get this?
Would be very pleasant if somebody can help a beginner :*-/
By teles the 17-05-2011 teles Hattrick team
By Marius_J the 20-05-2011
Thank you for answering! :)
By teles the 21-05-2011 teles Hattrick team
The callback url is the url where the user will be redirected after login on Hattrick website, it must be an url on your site in which you will receive data for getting OAuth token.
By WouterT the 21-05-2011
Thanks for this great program, but I've got a question; is it also possible to just save the xml generated by hattrick on my webserver and do imports from that file?
1. I've got a backup then.
2. I can use data from those files for "stuff" I add later on.
Thanks,
Wouter
By Marius_J the 21-05-2011
I am using the website tool "Joomla!" to build my website. U am a beginner with this, and I don't understand how I request token ect.
The codes above in the black boxes, where do I put them?
Thank you,
Marius_J
By teles the 21-05-2011 teles Hattrick team
You have to put this code somewhere in page, or module, ... which will do the chpp connection for your site.
By Marius_J the 22-05-2011
Could you please help me with a little description?
Thank you,
Marius_J
By teles the 25-05-2011 teles Hattrick team
By leroutard the 28-06-2011
I want to know if we can get all team from a leagueId ( poule en français) ?
If yes, which class handle this ? ( I can't find it )
Thanks
By teles the 28-06-2011 teles Hattrick team
You can search league with search xml file, yu got leagueUnitId, then with league xml file you can find team of this league.
By leroutard the 28-06-2011
By mrbrown79 the 26-07-2011
Great tool.
Do you have an overview of the memory usage of PHT?
In the code skeleton below, I try to get the player data from a large amount of leagues. At some point, I get a memory exhausted error. So my theory is that the memory usage accumulates for each TeamPlayers lookup.
Any comments on this theory?
$HT = new CHPPConnection('mSoqGeWBwLGPPCCKHLDwwT', 'xx','xx'');
$HT->setOauthToken($userToken);
$HT->setOauthTokenSecret($userTokenSecret);
for($leagueId=$firstLeague;$leagueIdgetLeague($leagueId);
for($i=1; $igetTeam($i);
$leagueTeamId = $leagueTeam->getTeamId();
$players = $HT->getTeamPlayers($leagueTeamId);
for($j=1; $jgetNumberPlayers(); $j++)
{
$player = $players->getPlayer($j);
$name = addslashes($player->getName());
$age = $player->getAge();
$salary = $player->getSalary() ;
$stamina = $player->getStamina();
$tsi = $player->getTsi() ;
$exp = $player->getExperience() ;
$id = $player->getId() ;
sql_insert(); // defined elsewhere
}
}
}
By mrbrown79 the 26-07-2011
Anyway, the code is three nested for loops.
1st running through leagues
2nd running through teams (of each league)
3rd running through players (of each team)
All is done on the same CHPPConnection.
Do you think, the memory usage of each player lookup will accumulate in such a case?
By teles the 26-07-2011 teles Hattrick team
By mrbrown79 the 27-07-2011
As the process of data collection is pretty time-consuming, I want it to be (close to) optimal with reference to processing time. Please, let me know if you have any tricks in regards to this :)
By teles the 27-07-2011 teles Hattrick team
you can call $HT->clearTeamPlayers($leagueTeamId);
When you call getTeam($id), after you get all you want you can call clearTeam($id)
It will clear pht cache (there is a cache on each xml file) and then you will consume less memory
By halftime the 10-08-2011
../trunk/PHT.php on line 13477"
function: $player->getRatingStarsAtEndOfMatch();
By guillermo the 22-10-2011
I have a nab doubt, when u say that we can save user token u mean on acutal session or in a db?
if its on db, when the user puts login i can manage the conecction to his team without doing 1st step?
i dont rly undertand steps. 1st one i give my chpp credentials and a url for users, they log in on hattrick and i get a request with their oauth_token and oauth_verifier.
retrieveAccessToken method is to validate that ? and after that i can store that access data in a db?
By teles the 26-10-2011 teles Hattrick team
Yes, retrieveAccessToken is to validate the token and give you real access to user data.
When you got the final token, you can save it to reuse later and avoid firsts login steps.
By Thomas the 16-11-2011
Fatal error: Call to undefined method HTTeam::getNumberFlagsHome()
I used the above example...
By Hoedinie the 22-11-2011 Hoedinie Hattrick team
By teles the 08-01-2012 teles Hattrick team
By teles the 08-01-2012 teles Hattrick team
When you retrieve the token in last step, you can save it on your side, as you want, and reuse it without doing whole auth process.
By Mark the 13-01-2012
By teles the 20-01-2012 teles Hattrick team
There is no easy way to get current week, you have to test if week match is played or not.
By fcheitenried the 06-03-2012
Want to have the whole table... how to do this...
By teles the 12-03-2012 teles Hattrick team
By fcheitenried the 22-03-2012
i tried with:
$HT->getLeague()->getLeagueTeam('1')->getPoints();
also tried with:
$HT->getLeague()->getLeagueTeam()->getTeam('1')->getPoints();
i wantet to have the points of the Team at first position. Do i am completly Wrong.
pls help
By teles the 12-04-2012 teles Hattrick team
You have to do: $HT->getLeague()->getTeam(1)->getPoints();