Last active
December 14, 2015 05:19
-
-
Save kosso/5034300 to your computer and use it in GitHub Desktop.
PHP to create an App.net streaming endpoint.
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
<? | |
// To create an App.net stream ... | |
$access_token = "YOUR_DEVELOPER_APP_ACCESS_TOKEN"; | |
// to get an App Access token, see here : http://developers.app.net/docs/authentication/flows/app-access-token/ | |
/* | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "https://account.app.net/oauth/access_token"); | |
$params = array('client_id' => $client_id, 'client_secret' => $client_secret, 'grant_type' => 'client_credentials'); | |
$p = http_build_query($params); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $p); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
$data = json_decode(curl_exec($ch)); | |
curl_close($ch); | |
if(!$data){ | |
echo '<h3>something went wrong</h3>'; | |
} else { | |
echo '<hr><h3>DONE!</h3>'; | |
echo '<pre>'; | |
print_r($data); | |
echo '</pre>'; | |
} | |
*/ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "https://alpha-api.app.net/stream/0/streams"); | |
curl_setopt($ch, CURLOPT_POST, TRUE); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
$jdata = Array(); | |
$jdata['type'] = 'long_poll'; | |
$types = Array(); | |
array_push($types, "post"); | |
$jdata['object_types'] = $types; | |
$jdata_string = json_encode($jdata); | |
//echo "<pre>"; | |
//print_r($jdata); | |
//echo "</pre><hr>"; | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $jdata_string); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
'Authorization: Bearer '.$access_token, | |
'Content-Type: application/json', | |
'Content-Length: ' . strlen($jdata_string)) | |
); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
$data = json_decode($data); | |
echo "<pre>"; | |
print_r($data); | |
echo "</pre>"; | |
// should return something like : | |
/* | |
stdClass Object | |
( | |
[data] => stdClass Object | |
( | |
[endpoint] => https://stream-channel.app.net/channel/1/blahblah2gyLKofOOWsdfdafadfasdfasdfasdfasfasdf44BFyRBJrxNJKzWrNDVwzNt5Wyxw2TH1UYJujo1Nvo1BxgMbswx1UqZ08KO9zJKz2o_pqv5SALJNWw7dBpY | |
[id] => 5 | |
[object_types] => Array | |
( | |
[0] => post | |
) | |
[type] => long_poll | |
) | |
[meta] => stdClass Object | |
( | |
[code] => 200 | |
) | |
) | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment