Merhaba arkadaşlar kod aşağıda
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Reddit API bilgileri
require 'vendor/autoload.php'; // Composer ile yüklenen kütüphane
use GuzzleHttpClient;
$redditClientId = 'clientId';
$redditClientSecret = 'clientSecret'';
$redditUsername = 'username';
$redditPassword = 'pass';
$redditUserAgent = 'MyAgent';
$redirectUri = 'redirectUrl'; // Bu, Reddit API'ye yönlendirme yapılacak URL'dir
$articleTitle = "hey";
$articleUrl = "redirectUrl";
$page = "Mypage";
// Kullanıcı adı ve şifre ile token alma yerine OAuth 2.0 yetkilendirme akışı kullanılıyor
$authUrl = 'https://www.reddit.com/api/v1/access_token';
$authData = [
'grant_type' => 'client_credentials',
'username' => $redditUsername,
'password' => $redditPassword,
];
$ch = curl_init($authUrl);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => $redditUserAgent,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => "$redditClientId:$redditClientSecret",
CURLOPT_POSTFIELDS => http_build_query($authData),
]);
$response = curl_exec($ch);
curl_close($ch);
$authResponse = json_decode($response, true);
if (isset($authResponse['access_token'])) {
$accessToken = $authResponse['access_token'];
$client = new Client();
$response = $client->post('https://oauth.reddit.com/api/submit', [
'headers' => [
'Authorization' => 'Bearer ' . $accessToken
],
'form_params' => [
'title' => $articleTitle,
'url' => $articleUrl,
'sr' => $page, // Subreddit adı
'api_type' => 'json'
]
]);
// Gönderim sonucunu kontrol et
$responseContent = json_decode($response->getBody()->getContents(), true);
if ($responseContent['json']['errors']) {
echo 'Link gönderme başarısız: ' . $responseContent['json']['errors'][0][1];
} else {
echo 'Link başarıyla gönderildi!';
}
}
?>
Bu kodda gelen hata "Please log in to do that. " oluyor. access token ı alıyor fakat post u paylaşmıyor. post olarak makale linkimi göndermek istiyorum redditte benim açtığım sayfaya, backlink alsın diye. bunda lütfen yardım edin
Reddit post api, 24 saattir deniyorum olmuyor
0
●74