Shamppi
Shamppi

Reputation: 445

Secure Instagram request with php using cURL

I've been struggling with this for a while now and still could not find a clear guide to do this.

If I want to make requests to Instagram API using cURL, I do it like this:

<?php

$url = "https://api.instagram.com/v1/users/self/?access_token=MY_TOKEN";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_exec($ch);

curl_close($ch);

?>

It works fine, but it's a bit insecure and thats why I'd like to do it with signed request, which uses this sig-parameter.

Now, I can easily create that sig-parameter(signature key) using the code found from here, but how to use that signature with PHP?

I'm totally confused.

Upvotes: 0

Views: 965

Answers (1)

coderz
coderz

Reputation: 1366

The answer is hinted at Instagram's documentation page. Still this is how I did:

  • Use the generate signature php function mentioned there to generate $sig.
  • Attach it to your endpoint using http_build_query() like this:

    $endpoint = "https://api.instagram.com/v1/users/self/";
    
    $secured_get_fields = array(
        "access_token" => $access_token,
        //other get fields as required
        "sig" => $sig
    );
    
    $api_url = $endpoint . "?" . http_build_query($secured_get_fields);
    
  • Call with this $api_url

Hope it helps!

Upvotes: 1

Related Questions