POST instagram api followed with cURL PHP

Hello!

I am trying to post the instagram API. I have one random valid access_token and I am trying to follow someone with only access_token using php and cURL, is this 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 am getting 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, for example) with only access_token, is that true?

Thank!

+3


source to share


1 answer


You may have enabled forced follow requests for your instagram client app. Therefore, you need to make a request with a signed header. See https://instagram.com/developer/restrict-api-requests/ for details . There they mentioned general responses to signed requests. We have to use access_token for some endpoints. And you are trying to make a post request, before you send a post request, make sure you have permission to send a post request to that endpoint. Reason for your response, Header is missing {"code": 403, "error_type": "OAuthForbiddenException", "error_message": "Invalid header: This operation requires X-Insta-Forwarded-For"}



+1


source







All Articles