Bonjour, je souhaite utiliser Oauth avec le site Mastodon pour pouvoir publier des messages. La Doc. Pour l’instant, j’arrive seulement à récupérer client_id et client_secret, je n’arrive pas plus loin. Voici mon code, et merci de votre aide !
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 | <?php # https://github.com/halcy/Mastodon.py/blob/master/mastodon/Mastodon.py # https://gist.github.com/aparrish/661fca5ce7b4882a8c6823db12d42d26 include 'config.php'; function requestspost($url, $data, $headers = false) { $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); if ($result === FALSE) { /* Handle error */ } return $result; } function requestsget($url, $token) { $opts = array( 'http'=>array( 'method'=>"GET", 'header'=>'Authorization: Bearer '.$token ) ); $context = stream_context_create($opts); return file_get_contents($url, false, $context); } ### CREATE APP ### $need_tokens = requestspost('https://'.INSTANCE.'/api/v1/apps', array('client_name'=>'PHP RSS2Mastodon Client','redirect_uris'=>'urn:ietf:wg:oauth:2.0:oob','scopes'=>'read write')); file_put_contents('tokens.json', $need_tokens); $token = json_decode(file_get_contents('tokens.json'), true); echo requestspost('https://'.INSTANCE.'/oauth/token', array('client_id'=>$token['client_id'], 'client_secret'=>$token['client_secret'], 'grand_type'=>'password', 'username'=>EMAIL, 'password'=>PASSWORD, 'scope'=>'read write')); |
+0
-0