• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

yks118/Mastodon-api-php-oauth: A GNU Social-compatible microblogging server htt ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

yks118/Mastodon-api-php-oauth

开源软件地址(OpenSource Url):

https://github.com/yks118/Mastodon-api-php-oauth

开源编程语言(OpenSource Language):

PHP 100.0%

开源软件介绍(OpenSource Introduction):

Mastodon-api-php-oauth

A GNU Social-compatible microblogging server https://mastodon.social PHP API

Mastodon REST API Document https://docs.joinmastodon.org

API Spec

PHP 7.1+

Test Spec

PHP 7.2+
Mastodon v2.9.2

How to use

// 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}']

	// App Regiter After
	'client_id'=>'{Your App Client Id}',
	'client_secret'=>'{Your App Client Secret}',

	// App Get access_token After
	'access_token'=>'{Your App access_token}'
];
$config = new \MastodonApi\MastodonApiConfig($params);
$mastodonApi = new \MastodonApi\MastodonApi($config);

Step 1. Register Your App

// 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

// 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
echo '<a href="' . $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

// 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

// 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);

Response Class

MastodonApi\Curl\Curl Object
(
    [method:MastodonApi\Curl\Curl:private] => 
    [url:MastodonApi\Curl\Curl:private] => 
    [options:MastodonApi\Curl\Curl:private] => Array
        (
        )

    [requestHeader:MastodonApi\Curl\Curl:private] => Array
        (
            [0] => Content-Type: application/json
        )

    [contentType:MastodonApi\Curl\Curl:private] => application/json
    [data] => 
    [responseData] => 
    [response] => MastodonApi\Curl\Response Object
        (
            [url] => 
            [contentType] => 
            [httpCode] => 0
            [headerSize] => 0
            [requestSize] => 0
            [sslVerifyResult] => 0
            [redirectCount] => 0
            [totalTime] => 0
            [namelookupTime] => 0
            [connectTime] => 0
            [pretransferTime] => 0
            [sizeUpload] => 0
            [sizeDownload] => 0
            [speedDownload] => 0
            [speedUpload] => 0
            [downloadContentLength] => -1
            [uploadContentLength] => -1
            [starttransferTime] => 0
            [redirectTime] => 0
            [redirectUrl] => 
            [primaryIp] => 
            [certinfo] => Array
                (
                )

            [primaryPort] => 0
            [localIp] => 
            [localPort] => 0
        )

    [error] => MastodonApi\Curl\Error Object
        (
            [code] => 
            [message] => 
        )

)

Use Data Class

var_dump($response->data);

Original Response Data Array

var_dump($response->responseData);



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap