Last active
July 4, 2017 09:43
-
-
Save treyssatvincent/b7da29d3332ec40585234826851bbbaf to your computer and use it in GitHub Desktop.
Faire fonctionner l'API sur Congressus ($config["discourse"]["api_key"] à ajouter dans les fichiers de config)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include_once("header.php"); | |
require_once("engine/discourse/DiscourseAPI.php"); | |
$apiUser = "USERNAME"; | |
$mailUser = "MAIL"; | |
$discourseApi = new richp10\discourseAPI\DiscourseAPI("discourse.partipirate.org", $config["discourse"]["api_key"], "https"); | |
// Tests : | |
$user = $discourseApi->getUserByEmail($mailUser); | |
$categories = $discourseApi->getCategories(); | |
// On récupere l'ID de la categorie Sandbox (ne fonctionne qu'en minuscule) | |
$category = $discourseApi->getCategory("sandbox"); | |
$categoryId = $category->apiresult->topic_list->topics[0]->category_id; | |
// Création d'un topic dont on récupere l'ID : | |
$new_topic = $discourseApi->createTopic("New topic from API", "Un topic de test fait depuis l'API.", $categoryId, $apiUser, $replyToId = 0); | |
$topicId = $new_topic->apiresult->topic_id; | |
sleep(1); // Necessaire pour la réponse dans la foulée | |
// On réponds au topic : | |
$answer = $discourseApi->createPost("Ceci est un test de réponse depuis l'API (En même temps que la création du topic).", $topicId, $apiUser); | |
// Affichage des test : | |
echo "<h2>user :</h2><pre>"; | |
print_r($user); | |
echo "</pre>"; | |
echo "<h2>categories :</h2><pre>"; | |
print_r($categories); | |
echo "</pre>"; | |
// Affichage de ce qui est utilisé pour poster : | |
echo "<h2>category :</h2><pre>"; | |
print_r($category); | |
echo "</pre>"; | |
echo "<h2>categoryId :</h2><pre>"; | |
print_r($categoryId); | |
echo "</pre>"; | |
echo "<h2>new_topic :</h2><pre>"; | |
print_r($new_topic); | |
echo "</pre>"; | |
echo "<h2>topicId :</h2><pre>"; | |
print_r($topicId); | |
echo "</pre>"; | |
echo "<h2>answer :</h2><pre>"; | |
print_r($answer); | |
echo "</pre>"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment