Question

Looking at http://instagram.com/developer/authentication/ - The recommended way of communication is serverside.

I understand how I do step1 and step2. But in step3 they want me POST data directly serverside? (I understand how I could do a post request from jQuery) But is it even possible to do directly from PHP/CodeIgniter?

This is basically step3:

In the previous step, you’ll have received a code which you’ll have to exchange in order to receive an access_token for the user. In order to make this exchange, you simply have to POST this code, along with some app identification parameters to our access_token endpoint.

I have all this info: (from response from Instagram)

client_id: your client id
client_secret: your client secret
grant_type: authorization_code is currently the only supported value
redirect_uri: the redirect_uri you used in the authorization request. Note: this has to be the same value as in the authorization request.
code: the exact code you received during the authorization step.
Was it helpful?

Solution

A backend can do a POST just like the browser. Much of the internet is server-to-server communication in this manner.

Here's an example POST request in PHP (using Curl)

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://www.example.com/site.html");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "postvar1=value1&postvar2=value2");

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec ($ch);

curl_close ($ch);

An alternative way to set the POST parameters instead of manually creating the param string:

curl_setopt($ch, CURLOPT_POSTFIELDS, 
         http_build_query(array('postvar1' => 'value1')));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top