Step 1. Register Your App

Last Update : 2019.07.06
// require MastodonApi autoload.php
require_once '{Your Server Path}/MastodonApi/autoload.php';

// set mastodon app data
$params = [
	'url'=>'{Mastodon URL : Ex. https://mastodon.manana.kr}',
	'redirect_uri'=>'{Your App Redirect Uri}',
	'scopes'=>['{Your App Scopes}']
];
$config = new \MastodonApi\MastodonApiConfig($params);
$mastodonApi = new \MastodonApi\MastodonApi($config);

// set apps request
$appsRequest = new \MastodonApi\Apps\AppsRequest();
$appsRequest->client_name = '{Your Client Name}';
$appsRequest->website = '{Your Website}';

// get apps response
$response = $mastodonApi->apps->apps($appsRequest);

Step 2 - 1. Get access_token - grant_type : authorization_code

Last Update : 2019.07.06
// require MastodonApi autoload.php
require_once '{Your Server Path}/MastodonApi/autoload.php';

// set mastodon app data
$params = [
	'url'=>'{Mastodon URL : Ex. https://mastodon.manana.kr}',
	'redirect_uri'=>'{Your App Redirect Uri}',
	'scopes'=>['{Your App Scopes}']

	// GET Step 1. Response Data
	'client_id'=>'{Your App Client Id}',
	'client_secret'=>'{Your App Client Secret}',
];
$config = new \MastodonApi\MastodonApiConfig($params);
$mastodonApi = new \MastodonApi\MastodonApi($config);

// get authorize URL
$url = $mastodonApi->oauth->authorize();

// use a tag
<a href="<?php echo $url; ?>">Authorize</a>

Callback Page

// require MastodonApi autoload.php
require_once '{Your Server Path}/MastodonApi/autoload.php';

// set mastodon app data
$params = [
	'url'=>'{Mastodon URL : Ex. https://mastodon.manana.kr}',
	'redirect_uri'=>'{Your App Redirect Uri}',
	'scopes'=>['{Your App Scopes}']

	// GET Step 1. Response Data
	'client_id'=>'{Your App Client Id}',
	'client_secret'=>'{Your App Client Secret}',
];
$config = new \MastodonApi\MastodonApiConfig($params);
$mastodonApi = new \MastodonApi\MastodonApi($config);

// get parameter check
if (isset($_GET['code']))
{
	// set return data
	$tokenRequest = new \MastodonApi\Oauth\Token\Request();
	$tokenRequest->code = $_GET['code'];
	$tokenRequest->grant_type = 'authorization_code';

	// get access token
	$response = $mastodonApi->oauth->token($tokenRequest);
}

Step 2 - 2. Get access_token - grant_type : password

Last Update : 2019.07.06
// require MastodonApi autoload.php
require_once '{Your Server Path}/MastodonApi/autoload.php';

// set mastodon app data
$params = [
	'url'=>'{Mastodon URL : Ex. https://mastodon.manana.kr}',
	'redirect_uri'=>'{Your App Redirect Uri}',
	'scopes'=>['{Your App Scopes}']

	// GET Step 1. Response Data
	'client_id'=>'{Your App Client Id}',
	'client_secret'=>'{Your App Client Secret}',
];
$config = new \MastodonApi\MastodonApiConfig($params);
$mastodonApi = new \MastodonApi\MastodonApi($config);

// set token request
$tokenRequest = new \MastodonApi\Oauth\Token\Request();
$tokenRequest->grant_type = 'password';
$tokenRequest->username = '{Mastodon Login E-Mail}';
$tokenRequest->password = '{Mastodon Login Password}';

// get access token
$response = $mastodonApi->oauth->token($tokenRequest);

Step 3. Enjoy Use MastodonApi

Last Update : 2019.07.06
// require MastodonApi autoload.php
require_once '{Your Server Path}/MastodonApi/autoload.php';

// set mastodon app data
$params = [
	'url'=>'{Mastodon URL : Ex. https://mastodon.manana.kr}',

	// GET Step 2. Response Data
	'access_token'=>'{Your App access_token}'
];
$config = new \MastodonApi\MastodonApiConfig($params);
$mastodonApi = new \MastodonApi\MastodonApi($config);

AdSense