Anonymous
Аутентификация с ошибкой только для приложения OAuth 2.0 при публикации Curl/PHP
Сообщение
Anonymous » 15 мар 2025, 11:53
Я собрал следующий код в попытке опубликовать в x: < /p>
Код: Выделить всё
$api_key='xx';
$api_secret='yy';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.twitter.com/oauth2/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded',
]);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $api_key.':'.$api_secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
$response = curl_exec($ch);
curl_close($ch);
$response=json_decode($response);
$access_token=$response->access_token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.twitter.com/2/tweets');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer '.$access_token,
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"text":"Hello, world!"}');
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
Я получаю access_token, но в конце концов мне представлена следующая ошибка: «Аутентификация с помощью OAuth 2.0 только приложение запрещено для этой конечной точки.>
Подробнее здесь:
https://stackoverflow.com/questions/795 ... hp-posting
1742028788
Anonymous
Я собрал следующий код в попытке опубликовать в x: < /p> [code]$api_key='xx'; $api_secret='yy'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.twitter.com/oauth2/token'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/x-www-form-urlencoded', ]); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $api_key.':'.$api_secret); curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials'); $response = curl_exec($ch); curl_close($ch); $response=json_decode($response); $access_token=$response->access_token; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.twitter.com/2/tweets'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: Bearer '.$access_token, 'Content-Type: application/json', ]); curl_setopt($ch, CURLOPT_POSTFIELDS, '{"text":"Hello, world!"}'); $response = curl_exec($ch); curl_close($ch); print_r($response); [/code] Я получаю access_token, но в конце концов мне представлена следующая ошибка: «Аутентификация с помощью OAuth 2.0 только приложение запрещено для этой конечной точки.> Подробнее здесь: [url]https://stackoverflow.com/questions/79510845/authenticating-with-oauth-2-0-application-only-error-when-curl-php-posting[/url]