phpapicurldiaspora

API to post messages on Diaspora 0.7.*


I've developped an API to post message on Diaspora. Everything works well on Diaspora 1.*. But when I try on Diaspora 0.7, I've the following error: "Page Not Found". So I think I am calling the wrong url. I did some research and couldn't find the right URL but I managed to get the access_token. Here is my code:

$DIASPORA_FR_URL = "https://diasporabr.com.br/";

$accessToken = "my_access_token";

$url = "{$DIASPORA_FR_URL}api/v1/posts?access_token=$accessToken";

$params = [
    "body" => "test",
    "public" => true
];

$data = http_build_query($params);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    $result = curl_error($ch);
}
curl_close($ch);

How to adapt this code to work with Diaspora 0.7.*?


Solution

  • The API was only really introduced in the currently unreleased next major version of diaspora*, see https://github.com/diaspora/diaspora/blob/develop/Changelog.md

    Thus the currently released stable version, 0.7, doesn't feature the API. Only installations running the latest development builds, that is some of the 0.7.99 versions or as you discovered yourself the current 1.0-dev versions support the API.