简体   繁体   English

使用cURL使用php保护Instagram请求

[英]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: 如果我想使用cURL向Instagram API发出请求,请按以下方式进行操作:

<?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. 它工作正常,但是有点不安全,这就是为什么我要使用带签名的request来执行此操作,该请求使用此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? 现在,我可以使用从此处找到的代码轻松创建sig -parameter(签名密钥),但是如何在PHP中使用该签名?

I'm totally confused. 我很困惑。

The answer is hinted at Instagram's documentation page. Instagram的文档页面提示了答案。 Still this is how I did: 仍然这是我的做法:

  • Use the generate signature php function mentioned there to generate $sig . 使用此处提到的生成签名php函数生成$sig
  • Attach it to your endpoint using http_build_query() like this: 使用http_build_query()将其附加到您的端点,如下所示:

     $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 调用此$api_url

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM