PHP code example of infinityxtech / slack-api-php

1. Go to this page and download the library: Download infinityxtech/slack-api-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

infinityxtech / slack-api-php example snippets


use SlackApi\Auth\SlackAuthProvider;
use SlackApi\Core\SlackApiProvider;

$clientId = getenv('SLACK_CLIENT_ID');
$clientSecret = getenv('SLACK_CLIENT_SECRET');
$redirectUrl = getenv('SLACK_REDIRECT_URL');

$provider = new SlackAuthProvider($clientId, $clientSecret, $redirectUrl);

// Call this when you wish to redirect user to authorize with slack
$provider->redirect();

// Call this on $redirectUrl when slack authorization redirect to $redirectUrl
$token = $provider->getAccessToken($_GET['code']);

// Create a new SlackApiProvider instance with access token
$slackApi = new SlackApiProvider($token);

// Below this point, you can use various API methods:
$slackApi->channel()->someMethod();
$slackApi->user()->someMethod();
$slackApi->chat()->someMethod();
$slackApi->auth()->someMethod();
$slackApi->apps()->someMethod();
$slackApi->conversations()->someMethod();
$slackApi->files()->someMethod();
$slackApi->reactions()->someMethod();
$slackApi->reminders()->someMethod();
$slackApi->teams()->someMethod();
$slackApi->userGroups()->someMethod();
$slackApi->views()->someMethod();