Skip to content

Instantly share code, notes, and snippets.

@localdisk
Created February 8, 2014 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save localdisk/8881906 to your computer and use it in GitHub Desktop.
Save localdisk/8881906 to your computer and use it in GitHub Desktop.
typetalk api use php (guzzle)
<?php
/**
* 前準備
* 1.Composer をインストールする(https://getcomposer.org/doc/00-intro.md)
* 2.Guzzle をインストール
{
"require": {
"guzzle/guzzle": "dev-master"
}
}
*/
require_once './vendor/autoload.php';
use Guzzle\Http\Client;
$clientId = 'xxxxxxxxxxxxxxxxxxxx';
$clientSecret = 'xxxxxxxxxxxxxxxxxxxx';
$topicId = 'xxx';
$msg = 'Hello, Typetalk!';
$client = new Client;
$res = $client->post('https://typetalk.in/oauth2/access_token', null, [
'client_id' => $clientId,
'client_secret' => $clientSecret,
'grant_type' => 'client_credentials',
'scope' => 'topic.post',
])->send();
$accessToken = json_decode($res->getBody('true'), true)['access_token'];
$client->post(
"https://typetalk.in/api/v1/topics/{$topicId}", ['Authorization' => 'Bearer ' . $accessToken], ['message' => $msg]
)->send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment