Created
February 7, 2014 19:51
-
-
Save localdisk/8870430 to your computer and use it in GitHub Desktop.
typetalk api php sample
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 | |
$clientId = 'xxxxxxxxxxxxxxxxxxxx'; | |
$clientSecret = 'xxxxxxxxxxxxxxxxxxxx'; | |
$topicId = 'xxx'; | |
$msg = 'Hello! typetalk! use PHP API!'; | |
$tokenQuery = http_build_query([ | |
'client_id' => $clientId, | |
'client_secret' => $clientSecret, | |
'grant_type' => 'client_credentials', | |
'scope' => 'topic.post' | |
]); | |
$tokenHeaders = [ | |
'Content-Type: application/x-www-form-urlencoded', | |
'Content-Length: ' . strlen($tokenQuery) | |
]; | |
$tokenContext = stream_context_create([ | |
'http' => [ | |
'method' => 'POST', | |
'content' => $tokenQuery, | |
'header' => [ | |
implode("\r\n", $tokenHeaders), | |
] | |
] | |
]); | |
$ret = file_get_contents('https://typetalk.in/oauth2/access_token', false, $tokenContext); | |
$accessToken = json_decode($ret, true)['access_token']; | |
$postQuery = http_build_query([ | |
'message' => $msg | |
]); | |
$postHeaders = [ | |
'Content-Type: application/x-www-form-urlencoded', | |
'Content-Length: ' . strlen($postQuery), | |
'Authorization: Bearer ' . $accessToken | |
]; | |
$postContext = stream_context_create([ | |
'http' => [ | |
'method' => 'POST', | |
'content' => $postQuery, | |
'header' => [ | |
implode("\r\n", $postHeaders), | |
] | |
] | |
]); | |
file_get_contents("https://typetalk.in/api/v1/topics/{$topicId}", false, $postContext); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment