I'm new in instagram, base on Real-time Photo Updates. Don't understand the process, can anyone enlighten me how to create callback URL in php? From the register client's redirect uri need to link up to this callback URL? The below code is how i did for the callback URL
$checkin_url = "https://api.instagram.com/v1/subscriptions/";
//$instagram[] for client_id, client_secret, redirect_uri
$parameters = array(
'client_id' => $instagram['client_id'],
'client_secret' => $instagram['client_secret'],
'object' => 'tag',
'aspect' => 'media',
'object_id' => 'nofilter',
'callback_url' => $instagram['redirect_uri']
);
$curl = curl_init($checkin_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
print($response);
You missed an important step in the subscription process (It's in the doc):
In other word, when you create the subscription, they send a GET request to your callback URI with some parameters, and you have to return the
hub.challenge
parameters (hub_challenge
in PHP, because with PHP the parameters with a.
are converted to_
).So in your callback URI, you have to test the request method. If it's
GET
, do the following :and if it's
POST
, it's a subscription update, so you have to json decode the raw body to get the datas, as stated in the doc' :)