Created
February 8, 2014 10:56
-
-
Save localdisk/8881906 to your computer and use it in GitHub Desktop.
typetalk api use php (guzzle)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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