为什么我在hub_challenge中获得额外空间? (Instagram订阅)

时间:2017-09-11 16:20:22

标签: php instagram instagram-api

我尝试用PHP中的cURL方法制作Instagram订阅。每一个看起来都很好,但我收到了这个奇怪的回应:

{"meta": {
"code": 400, 
"error_type": "APISubscriptionError", 
"error_message": "Challenge verification failed. 
Sent \"361de01a08534930bd9af728a62ca8cd\", 
received \"b' 361de01a08534930bd9af728a62ca8cd'\"."}}

我花了一整天的时间试图破译这个,但我不知道这里发生了什么。 谢谢大家!

subscribe.php

<?php
require_once "pass.php"; //Here I have all pass and ids

$client_id = '$insta->$client_id';
$client_secret = '$insta->$client_secret';
$object = 'user';
$object_id = 'self';
$aspect = 'media';
$verify_token='asd';
$callback_url = 'https://myURL/InstaTest/callback.php';

$attachment =  array(
'client_id' => $client_id,
'client_secret' => $client_secret,
'object' => $object,
'object_id' => $object_id,
'aspect' => $aspect,
'verify_token' => $verify_token,
'callback_url'=>$callback_url
);

$url = "https://api.instagram.com/v1/subscriptions/";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output 
$result = curl_exec($ch);
curl_close ($ch);

print_r($result);


?>

callback.php

 <?php
if (isset ($_GET['hub_challenge'])){
    echo $_GET['hub_challenge'];
}

//This is an update
else {

    $myString = file_get_contents('php://input');
    $answer = json_decode($myString);
    echo $answer;
}
?>

0 个答案:

没有答案