sendpulse api пример получания token ключа и получение email’ов
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
<?php $token = $_COOKIE['sendpulse_token']; /** * @param NULL * @return mixed */ function getToken () { $tokenArr = array( 'grant_type' => 'client_credentials', 'client_id' => 'id', 'client_secret' => 'id_secret' ); $tokenGo = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query($tokenArr) ) ); $tokenMass = file_get_contents("https://api.sendpulse.com/oauth/access_token", false, stream_context_create($tokenGo)); $json = json_decode($tokenMass); return $json->access_token; } function getEmails ($token) { $tokenArr = array( 'grant_type' => 'client_credentials', 'access_token' => $token, 'token_type' => 'Bearer' ); $tokenGo = array( 'http' => array( 'method' => 'GET', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query($tokenArr) ) ); $tokenMass = file_get_contents("https://api.sendpulse.com/addressbooks", false, stream_context_create($tokenGo)); $json = json_decode($tokenMass); return $json; } if (!$_COOKIE['sendpulse_token']) { setcookie('sendpulse_token', getToken(), time()+3600); echo "token install!!!"; } else { echo "token found!!!<br/>"; echo $token; } echo "<hr/>"; var_dump(getEmails($token)); |