Omid Reza Heidari
Omid Reza Heidari

Reputation: 688

Send JSON with PHP

I want to follow with Instagram API in PHP, but it shows an error:

Fatal error: Uncaught Error: Call to undefined function sendPostData() in /storage/h11/133/1908133/public_html/index.php:13 Stack trace: #0 {main} thrown in /storage/h11/133/1908133/public_html/index.php on line 13

My code:

<html>
<head>
<title>indexer</title>
</head>
<body>
</body>
</html>
<?php
$access = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$user_id = 'xxxxxxxx';
$url= 'https://api.instagram.com/v1/users/'.$user_id.'/relationship?access_token='.$access;
$data = 'action=follow';
$resultObj = json_decode(sendPostData($url,$data));
print_r($resultObj);
?>

Upvotes: 0

Views: 170

Answers (2)

Prafulla Kumar Sahu
Prafulla Kumar Sahu

Reputation: 9693

What you want to get or to modify first be clear about it. if you want to retrieve it needs a GET request - Get information about a relationship to another user.

  $request_uri =  https://api.instagram.com/v1/users/{user-id}/relationship?access_token=ACCESS-TOKEN

and if you want to modify something - Modify the relationship between the current user and the target user.

   $request_uri = https://api.instagram.com/v1/users/{user-id}/relationship?access_token=ACCESS-TOKEN

about curl request

$request_uri = 'https://api.instagram.com/v1/users/{user-id}/relationship';

$ch = curl_init();
$curlConfig = array(
    CURLOPT_URL            => $request_uri,
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS     => array(
        'access_token' => ACCESS-TOKEN,
    )
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
var_dump($result);
curl_close($ch);

Hope this will be helpful to you.

Upvotes: 1

Harsh Panchal
Harsh Panchal

Reputation: 308

You can try this

$resultObj = json_decode(file_get_contents($url,$data));

Hope it will work

Upvotes: 1

Related Questions