2019-12-10 03:36:52 +00:00
|
|
|
# Using the APIs
|
2017-12-19 11:07:31 +00:00
|
|
|
|
|
|
|
<!-- markdownlint-disable MD010 MD013 MD024 -->
|
2017-05-11 12:54:26 +00:00
|
|
|
|
|
|
|
* [Home](help)
|
|
|
|
|
2019-12-10 03:36:52 +00:00
|
|
|
Friendica offers multiple API endpoints to interface with third-party applications:
|
2017-05-11 12:54:26 +00:00
|
|
|
|
2019-12-10 03:36:52 +00:00
|
|
|
- [Twitter](help/API-Twitter)
|
|
|
|
- [Mastodon](help/API-Mastodon)
|
|
|
|
- [Friendica-specific](help/API-Friendica)
|
|
|
|
- [GNU Social](help/API-GNU-Social)
|
2017-05-11 12:54:26 +00:00
|
|
|
|
2019-12-10 03:36:52 +00:00
|
|
|
## Usage
|
2017-05-11 12:54:26 +00:00
|
|
|
|
2019-12-10 03:36:52 +00:00
|
|
|
### HTTP Method
|
2017-12-19 11:07:31 +00:00
|
|
|
|
2019-12-10 03:36:52 +00:00
|
|
|
API endpoints can restrict the HTTP method used to request them.
|
2017-05-11 12:54:26 +00:00
|
|
|
Using an invalid method results in HTTP error 405 "Method Not Allowed".
|
|
|
|
|
2019-12-10 03:36:52 +00:00
|
|
|
### Authentication
|
2017-12-19 11:07:31 +00:00
|
|
|
|
2021-07-20 20:48:37 +00:00
|
|
|
Friendica supports basic HTTP Auth and OAuth to authenticate the user to the APIs.
|
2017-12-19 11:07:31 +00:00
|
|
|
|
2019-12-10 03:36:52 +00:00
|
|
|
### Errors
|
2017-12-19 11:07:31 +00:00
|
|
|
|
2017-05-19 20:37:45 +00:00
|
|
|
When an error occurs in API call, an HTTP error code is returned, with an error message
|
2017-05-11 12:54:26 +00:00
|
|
|
Usually:
|
2017-12-19 11:07:31 +00:00
|
|
|
|
|
|
|
* 400 Bad Request: if parameters are missing or items can't be found
|
|
|
|
* 403 Forbidden: if the authenticated user is missing
|
|
|
|
* 405 Method Not Allowed: if API was called with an invalid method, eg. GET when API require POST
|
|
|
|
* 501 Not Implemented: if the requested API doesn't exist
|
|
|
|
* 500 Internal Server Error: on other error conditions
|
2017-05-11 12:54:26 +00:00
|
|
|
|
|
|
|
Error body is
|
|
|
|
|
|
|
|
json:
|
2017-12-19 11:07:31 +00:00
|
|
|
|
|
|
|
```json
|
2019-07-30 05:36:06 +00:00
|
|
|
{
|
2019-12-10 03:36:52 +00:00
|
|
|
"error": "Specific error message",
|
|
|
|
"request": "API path requested",
|
|
|
|
"code": "HTTP error code"
|
2019-07-30 05:36:06 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-12-19 11:07:31 +00:00
|
|
|
xml:
|
|
|
|
|
|
|
|
```xml
|
2019-12-10 03:36:52 +00:00
|
|
|
<status>
|
|
|
|
<error>Specific error message</error>
|
|
|
|
<request>API path requested</request>
|
|
|
|
<code>HTTP error code</code>
|
|
|
|
</status>
|
2017-05-11 12:54:26 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Usage Examples
|
2017-12-19 11:07:31 +00:00
|
|
|
|
2017-05-11 12:54:26 +00:00
|
|
|
### BASH / cURL
|
|
|
|
|
2017-12-19 11:07:31 +00:00
|
|
|
```bash
|
2017-05-11 12:54:26 +00:00
|
|
|
/usr/bin/curl -u USER:PASS https://YOUR.FRIENDICA.TLD/api/statuses/update.xml -d source="some source id" -d status="the status you want to post"
|
2017-12-19 11:07:31 +00:00
|
|
|
```
|
2017-05-11 12:54:26 +00:00
|
|
|
|
|
|
|
### Python
|
2017-12-19 11:07:31 +00:00
|
|
|
|
|
|
|
The [RSStoFriendika](https://github.com/pafcu/RSStoFriendika) code can be used as an example of how to use the API with python.
|
2017-09-24 10:05:28 +00:00
|
|
|
The lines for posting are located at [line 21](https://github.com/pafcu/RSStoFriendika/blob/master/RSStoFriendika.py#L21) and following.
|
2017-05-11 12:54:26 +00:00
|
|
|
|
2023-05-13 23:43:07 +00:00
|
|
|
def tweet(server, message, circle_allow=None):
|
2017-05-11 12:54:26 +00:00
|
|
|
url = server + '/api/statuses/update'
|
2023-05-13 23:43:07 +00:00
|
|
|
urllib2.urlopen(url, urllib.urlencode({'status': message, 'circle_allow[]': circle_allow}, doseq=True))
|
2017-05-11 12:54:26 +00:00
|
|
|
|
|
|
|
There is also a [module for python 3](https://bitbucket.org/tobiasd/python-friendica) for using the API.
|