Bu kod isinizi gormesi lazim tokeniniz var ise bana vermiyorlar bir türlü 🥸
function postToInstagram($imagePath, $caption, $accessToken) {
$url = 'https://graph.instagram.com/v12.0/{user_id}/media';
$imageUploadData = [
'image_url' => $imagePath,
'caption' => $caption,
'access_token' => $accessToken,
];
$response = file_get_contents($url, false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode($imageUploadData),
]
]));
$responseData = json_decode($response, true);
if (isset($responseData['id'])) {
$publishUrl = 'https://graph.instagram.com/v12.0/{user_id}/media_publish';
$publishData = [
'creation_id' => $responseData['id'],
'access_token' => $accessToken,
];
$publishResponse = file_get_contents($publishUrl, false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode($publishData),
]
]));
return json_decode($publishResponse, true);
} else {
return $responseData;
}
}