Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST instagram api follow with cURL PHP

¡Hi!

I'm trying to post with instagram API. I have one random valid access_token and I'm trying to follow someone only with the access_token using php and cURL, is it possible?

My PHP CODE:

$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL,"https://api.instagram.com/v1/users/<userid>/relationship?access_token=<valid access_token>");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'action=follow');
// grab URL and pass it to the browser
$result = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);

print_r($result);

And i get this error:

{"code": 403, "error_type": "OAuthForbiddenException", "error_message": "Invalid header: X-Insta-Forwarded-For is required for this operation"}

I read that I can do actions (follow, like) with only access_token, is it truth?

Thanks!

like image 436
seergiue Avatar asked Feb 28 '26 21:02

seergiue


1 Answers

You might have enabled enforce signed requests for your instagram client app. So you need to make request with a signed header. For more details visit the following https://instagram.com/developer/restrict-api-requests/ . There they mentioned the common responses for signed requests. We should use access_token for some endpoints. And you are trying to make a post request, before making post request make sure that you have the permission to make a post request on that endpoint. The reason for your response, Header is missing {"code": 403, "error_type": "OAuthForbiddenException", "error_message": "Invalid header: X-Insta-Forwarded-For is required for this operation"}

like image 96
Rishikesan Varudharajan Avatar answered Mar 03 '26 11:03

Rishikesan Varudharajan